Skip to content

Commit

Permalink
use /proc/net/tcp to check if lime is loaded instead of netstat
Browse files Browse the repository at this point in the history
  • Loading branch information
joelferrier committed Feb 11, 2017
1 parent 056d03f commit c3bc72d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions margaritashotgun/remote_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from margaritashotgun.ssh_tunnel import SSHTunnel
from margaritashotgun.repository import Repository
from margaritashotgun.memory import Memory, OutputDestinations
from margaritashotgun.util import parser

try:
from logging.handlers import QueueHandler
Expand Down Expand Up @@ -120,6 +121,7 @@ def __init__(self):
self.shell = RemoteShell()
self.commands = Commands
self.tunnel = SSHTunnel()
self.net_parser = parser.ProcNetTcpParser()

def connect(self, username, password, key, address, port, jump_host):
"""
Expand Down Expand Up @@ -206,12 +208,12 @@ def wait_for_lime(self, listen_port, listen_address="0.0.0.0",
listen_port)
lime_loaded = False
while tries < max_tries and lime_loaded is False:
lime_loaded = self.check_for_lime(pattern, listen_port)
lime_loaded = self.check_for_lime(pattern)
tries = tries + 1
time.sleep(wait)
return lime_loaded

def check_for_lime(self, pattern, listen_port):
def check_for_lime(self, pattern):
"""
Check to see if LiME has loaded on the remote system
Expand All @@ -220,14 +222,19 @@ def check_for_lime(self, pattern, listen_port):
:type listen_port: int
:param listen_port: port LiME is listening for connections on
"""
check = self.commands.lime_check.value.format(listen_port)
check = self.commands.lime_check.value
lime_loaded = False
result = self.shell.execute(check)
stdout = self.shell.decode(result['stdout'])
stderr = self.shell.decode(result['stderr'])
if pattern in stdout:
return True
else:
return False
connections = self.net_parser.parse(stdout)

for conn in connections:
local_addr, remote_addr = conn
if local_addr == pattern:
lime_loaded = True
break

return lime_loaded

def upload_module(self, local_path=None, remote_path="/tmp/lime.ko"):
"""
Expand Down
2 changes: 1 addition & 1 deletion margaritashotgun/remote_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Commands(Enum):
mem_size = "cat /proc/meminfo | grep MemTotal | awk '{ print $2 }'"
kernel_version = "uname -r"
lime_pattern = "{0}:{1}"
lime_check = "netstat -lnt | grep {0}"
lime_check = "cat /proc/net/tcp"
load_lime = 'sudo insmod {0} "path=tcp:{1}" format={2}'
unload_lime = "sudo pkill insmod; sudo rmmod lime"

Expand Down

0 comments on commit c3bc72d

Please sign in to comment.