티스토리 뷰

프로젝트

[cuckoo] cuckoo sandbox api 이용하기

삼전동해커 2022. 11. 3. 16:59

https://cuckoo.readthedocs.io/en/latest/usage/api/

 

REST API — Cuckoo Sandbox v2.0.7 Book

Following is a list of currently available resources and a brief description of each one. For details click on the resource name. /cuckoo/status GET /cuckoo/status/ Returns status of the cuckoo server. In version 1.3 the diskspace entry was added. The disk

cuckoo.readthedocs.io

cuckoo sandbox에서 rest api를 활용해 자동으로 멀웨어 샘플을 전달하는 코드를 작성했다.

먼저 다음을 설치해준다.

sudo apt-get install uwsgi

이 후 cuckoo가 활성화 된 상태로 다음 명령어로 rest api web을 활성화 시킨다.

cuckoo api

 

혹시 다음과 같은 에러가 발생하면

AttributeError: 'Request' object has no attribute 'is_xhr'

다음 명령어를 실행하자.

pip install werkzeug==0.16.1

이제 브라우저에서 localhost:8090으로 접속하면 된다.

import requests
import os


REST_URL = "http://localhost:8090/tasks/create/file"

HEADERS = { "Authorization": "Bearer your_token_here",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}

#본인은 샘플들을 test, exe, html, binary 등으로 분류했기 때문에 하나 상위 디렉을 기본으로 잡았고 
main문에서 원하는 디렉토리를 선택한다.
mal_path = "/home/crypto/Desktop/mal"

#원하는 디렉토리의 pwd를 가져오기 위한 get_path 함수
def get_path(dir):
    return os.path.join(mal_path,dir)

#get_path로 가져온 pwd로 cuckoo에 전송
def api(dir):
    mal_dir = get_path(dir)
    mal_list = os.listdir(mal_dir)

    for mal in mal_list:
        with open((os.path.join(mal_dir,mal)),'rb') as sa:
            files = {"file":("test",sa)}
            r = requests.post(REST_URL, headers=HEADERS,files = files)
        task_id = r.json()['task_id']

#main 문
if __name__ == "__main__":
    api("test")

위 코드를 이용해 cuckoo sandbox에 멀웨어 파일을 자동으로 전송하고 리포트를 받을 수 있다.

먼저 HEADERS 부분에 ~/.cuckoo/conf/cuckoo.conf에 있는 token 값을 넣어야한다. 토큰 값이 유출되지 않게 주의하자.

디렉토리 부분은 개인이 맞게 수정하고 코드를 실행 시키면 된다.

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함