Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amun lyz #12

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
089efcf
Update amun_request_handler.py
aichimzh Apr 25, 2024
7c9c54f
Update README.md
aichimzh Apr 25, 2024
617d254
Update amun_request_handler.py
aichimzh Apr 25, 2024
ec595e1
Add your commit message here
May 2, 2024
c8b23aa
Delete ConnectionDuration.log
aichimzh May 2, 2024
9c99c87
Update shellcode_mgr_core.py
aichimzh May 2, 2024
61c7087
Update shellcode_mgr_core.py
aichimzh May 2, 2024
cfeb51c
Update shellcode_mgr_core.py
aichimzh May 2, 2024
9b4e98c
Update shellcode_mgr_core.py
aichimzh May 2, 2024
c8b7d29
Update shellcode_mgr_core.py
aichimzh May 2, 2024
23e8592
Update shellcode_mgr_core.py
aichimzh May 2, 2024
aed175c
Update shellcode_mgr_core.py
aichimzh May 3, 2024
d675612
Update shellcode_mgr_core.py
aichimzh May 3, 2024
04bfbb5
Update shellcode_mgr_core.py
aichimzh May 3, 2024
53abbfb
Update shellcode_mgr_core.py
aichimzh May 3, 2024
04232bd
Update shellcode_mgr_core.py
aichimzh May 3, 2024
52a0a38
Update shellcode_mgr_core.py
aichimzh May 5, 2024
a2495a4
Update shellcode_mgr_core.py
aichimzh May 5, 2024
e2eb380
Update shellcode_mgr_core.py
aichimzh May 5, 2024
abf9e3b
Update shellcode_mgr_core.py
aichimzh May 5, 2024
74c494a
Update shellcode_mgr_core.py
aichimzh May 5, 2024
712d755
Update amun.conf
aichimzh May 5, 2024
409dd92
Update shellcode_mgr_core.py
aichimzh May 5, 2024
ae9810f
Update shellcode_mgr_core.py
aichimzh May 5, 2024
f39c204
Update shellcode_mgr_core.py
aichimzh May 6, 2024
a0d4128
Update shellcode_mgr_core.py
aichimzh May 16, 2024
36f0786
Update amun.conf
aichimzh May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ more sophisticated emulation and easier maintenance.

## Installation

* Clone Git repository: `git clone https://github.com/zeroq/amun.git`
* Clone Git repository: `git clone -b Amun-lyz https://github.com/aichimzh/amun.git`
* Edit Amun main configuration file: `vim conf/amun.conf`
* for example set the ip address for Amun to listen on (0.0.0.0 to listen on all)
* enable or disbale vulnerability modules as needed
Expand Down
21 changes: 20 additions & 1 deletion core/amun_request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from psyco.classes import *
except ImportError:
pass


import logging
import asynchat
import StringIO
import traceback
Expand Down Expand Up @@ -56,6 +57,16 @@ def __init__(self, divLogger):
self.proxyResult = None
self.sendRequest = ""
self.log_obj = amun_logging.amun_logging("amun_request_handler", divLogger['requestHandler'])
self.logger = logging.getLogger('connection_logger')
self.logger.setLevel(logging.DEBUG)
log_file = 'ConnectionDuration.log'
file_handler = logging.FileHandler(log_file)
file_handler.setLevel(logging.DEBUG)
if not self.logger.handlers:
self.logger.addHandler(file_handler)
self.divLogger = divLogger
self.start_time = time.time()
self.end_time = None

def __del__(self):
pass
Expand Down Expand Up @@ -144,6 +155,14 @@ def setup_remote_connection(self, remote_ip=None):
raise

def handle_close(self):
self.end_time = time.time()
duration = self.end_time - self.start_time
msg = "Remote IP: {}, Remote port: {}, Own port: {}, ConnectionDuration: {} seconds".format(self.remote_ip,
self.remote_port,
self.own_port,
duration)
print(msg)
self.logger.debug("({}),".format(msg))
try:
self.connected = False
try:
Expand Down
97 changes: 72 additions & 25 deletions core/shellcode_mgr_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
try:
import psyco ; psyco.full()
from psyco.classes import *
import os
import requests
except ImportError:
pass

Expand All @@ -26,12 +28,13 @@
from sys import exit, stdout
from StringIO import StringIO
import traceback

import requests
from iprange import IPRange
from amun_logging import amun_logging

class shell_mgr:
def __init__(self, decodersDict, shLogger, config_dict):
def __init__(self, decodersDict, shLogger, config_dict, hexdump_dir="hexdumps"):

"""initialize shellcode decoder class

Keyword arguments:
Expand All @@ -53,6 +56,8 @@ def __init__(self, decodersDict, shLogger, config_dict):
self.log_obj = amun_logging("shellcode_manager", shLogger)
### load shellcodes
self.decodersDict = decodersDict
self.hexdump_dir = hexdump_dir


def getNewResultSet(self, vulnName, attIP, ownIP):
"""Return a new empty result set to be used for detected shellcode
Expand Down Expand Up @@ -1784,40 +1789,82 @@ def handle_lichtenfels(self, key, dec_shellcode):
return True
return False

def write_hexdump(self, shellcode=None, extension=None, ownPort="None"):
"""Write unknown/undetected shellcode as a hexdump to disc for later analysis

Keyword arguments:
shellcode -- specific shellcode that was not detected (default None, i.e. use global self.shellcode)
extension -- use specifial extension on stored hexdump (default None)
ownPort -- attach the network port of the vulnerability that was exploited to filename (default "None")

"""
if not shellcode:


def write_hexdump(self, shellcode=None, extension=None, ownPort="None"):
if not shellcode:
file_data = "".join(self.shellcode)
else:
else:
file_data = "".join(shellcode)
### ignore zero size hexdumps
if len(file_data)==0 or (extension=="MS03049" and (file_data.count('PIPE')>=2 or file_data.count('\x50\x00\x49\x00\x50\x00\x45')>=2)) or len(file_data)<100:
if len(file_data)==0 or (extension=="MS03049" and (file_data.count('PIPE')>=2 or file_data.count('\x50\x00\x49\x00\x50\x00\x45')>=2)) or len(file_data)<100:
return
### generate md5 fingerprint of shellcode
hash = md5(file_data)
digest = hash.hexdigest()
if extension!=None:
hash = md5(file_data)
digest = hash.hexdigest()
if extension!=None:
filename = "hexdumps/%s-%s-%s.hex" % (extension.strip(), digest, ownPort)
else:
else:
filename = "hexdumps/%s-%s.hex" % (digest, ownPort)
### write hexdump to disc
if not ospath.exists(filename):



if not ospath.exists(filename):
response = self.query_virustotal(digest)
if response:
print(digest + "Recorded by VirusTotal")


try:
fp = open(filename, 'a+')
fp.write(file_data)
fp.close()
self.log_obj.log("(%s) no match, writing hexdump (%s :%s) - %s" % (self.attIP, digest, len(file_data), self.resultSet['vulnname']), 9, "warn", True, True)
except IOError, e:
self.log_obj.log("(%s) failed writing hexdump (%s) (%s :%s) - %s" % (self.attIP, e, digest, len(file_data), self.resultSet['vulnname']), 9, "crit", True, True)
fp = open(filename, 'a+')
fp.write(file_data)
fp.close()
filename = filename.replace(".hex", "_recorded(VT).hex")
self.log_obj.log("(%s) no match, writing hexdump (%s :%s) - %s Recorded by VT" % (self.attIP, digest, len(file_data), self.resultSet['vulnname']), 9, "warn", True, True)
except IOError, e:
self.log_obj.log("(%s) failed writing hexdump (%s) (%s :%s) - %s" % (self.attIP, e, digest, len(file_data), self.resultSet['vulnname']), 9, "crit", True, True)

return False

else:
try:
fp = open(filename, 'a+')
fp.write(file_data)
fp.close()
self.log_obj.log("(%s) no match, writing hexdump (%s :%s) - %s" % (self.attIP, digest, len(file_data), self.resultSet['vulnname']), 9, "warn", True, True)
except IOError, e:

self.log_obj.log("(%s) failed writing hexdump (%s) (%s :%s) - %s" % (self.attIP, e, digest, len(file_data), self.resultSet['vulnname']), 9, "crit", True, True)


return False


return True


def query_virustotal(hash, api_key="your_VT_APIkey"):

url = 'https://www.virustotal.com/api/v3/file/%s' % hash
headers = {'x-apikey': api_key}
response = requests.get(url, headers=headers)
print(response.status_code)

if response.status_code == 200:

result = True



return result
else:

result = False


return result


def match_direct_file(self, dec_shellcode=None):
"""Check if given shellcode is an executable file
Expand Down