22
33from routersploit .core .exploit .exploit import Exploit
44from routersploit .core .exploit .exploit import Protocol
5+ from routersploit .core .exploit .option import OptBool
56from routersploit .core .exploit .printer import print_status
67from routersploit .core .exploit .printer import print_error
78from routersploit .core .exploit .utils import is_ipv4
@@ -16,13 +17,15 @@ class TCPClient(Exploit):
1617
1718 target_protocol = Protocol .TCP
1819
20+ verbosity = OptBool ("true" , "Enable verbose output: true/false" )
21+
1922 def tcp_create (self ):
2023 if is_ipv4 (self .target ):
2124 tcp_client = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
2225 elif is_ipv6 (self .target ):
2326 tcp_client = socket .socket (socket .AF_INET6 , socket .SOCK_STREAM )
2427 else :
25- print_error ("Target address is not valid IPv4 nor IPv6 address" )
28+ print_error ("Target address is not valid IPv4 nor IPv6 address" , verbose = self . verbosity )
2629 return None
2730
2831 tcp_client .settimeout (TCP_SOCKET_TIMEOUT )
@@ -33,12 +36,12 @@ def tcp_connect(self):
3336 tcp_client = self .tcp_create ()
3437 tcp_client .connect ((self .target , self .port ))
3538
36- print_status ("Connection established" )
39+ print_status ("Connection established" , verbose = self . verbosity )
3740 return tcp_client
3841
3942 except Exception as err :
40- print_error ("Could not connect" )
41- print_error (err )
43+ print_error ("Could not connect" , verbose = self . verbosity )
44+ print_error (err , verbose = self . verbosity )
4245
4346 return None
4447
@@ -47,7 +50,7 @@ def tcp_send(self, tcp_client, data):
4750 if type (data ) is bytes :
4851 return tcp_client .send (data )
4952 else :
50- print_error ("Data to send is not type of bytes" )
53+ print_error ("Data to send is not type of bytes" , verbose = self . verbosity )
5154
5255 return None
5356
@@ -67,9 +70,9 @@ def tcp_recv(self, tcp_client, num):
6770
6871 return response
6972 except socket .timeout :
70- print_error ("Socket did timeout" )
73+ print_error ("Socket did timeout" , verbose = self . verbosity )
7174 except socket .error :
72- print_error ("Socket error" )
75+ print_error ("Socket error" , verbose = self . verbosity )
7376
7477 return None
7578
0 commit comments