forked from infobyte/faraday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_history.py
74 lines (59 loc) · 1.81 KB
/
commands_history.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Faraday Penetration Test IDE
Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/)
See the file 'doc/LICENSE' for the license information
'''
import uuid
import socket
import subprocess
import getpass
def get_private_ip():
"""
This method returns the first private ip address
configured for this machine.
TODO: The problem is what happens when the machine
has more than one private ip
"""
# What's the best way to do this?
ip = socket.gethostbyname(socket.gethostname())
if ip:
if not ip.startswith('127'):
return ip
ip = socket.gethostbyname(socket.getfqdn())
if ip:
if not ip.startswith('127'):
return ip
ip = subprocess.check_output(["ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'"], shell=True)
return ip
def get_hostname():
return socket.gethostname()
def get_user():
return getpass.getuser()
class CommandRunInformation(object):
"""Command Run information object containing:
command, parameters, time, workspace, etc."""
class_signature = "CommandRunInformation"
def __init__(self, **kwargs):
self._id = uuid.uuid4().hex
self.type = self.__class__.__name__
self.user = get_user()
self.ip = get_private_ip()
self.hostname = get_hostname()
self.itime = None
self.duration = None
self.params = None
self.workspace = None
for k, v in kwargs.items():
setattr(self, k, v)
def getID(self):
return self._id
def setID(self, id):
return self._id
def toDict(self):
return self.__dict__
def fromDict(self, dictt):
for k, v in dictt.items():
setattr(self, k, v)
return self