forked from EmpireProject/Empire
-
-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nameserver: discover nameserver within environment of this host (#741)
* nameserver: discover nameserver within environment of this host * CHANGELOG.md: Update the changelog * fixit! Add CHANGELOG.md verbiage that was removed * Update CHANGELOG.md Co-authored-by: Vincent Rose <[email protected]> * fixit! Update author name as string Seems the author name is being interpreted as byte data using the GitHub install. --------- Co-authored-by: Vincent Rose <[email protected]>
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
empire/server/data/module_source/python/discovery/nameserver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
"""Module for finding local nameserver | ||
Retrieve the local nameserver from resolv.conf | ||
Author: 0x636f646f | ||
""" | ||
|
||
import glob | ||
import re | ||
|
||
|
||
def check_for_resolv() -> list: | ||
"""Check for the resolv.conf file""" | ||
resolv_conf_file = glob.glob('/etc/resolv.conf') | ||
if resolv_conf_file: | ||
return resolv_conf_file | ||
return [] | ||
|
||
|
||
def list_check(resolv_file) -> None: | ||
"""Return exception if list empty""" | ||
if resolv_file: | ||
return | ||
if not resolv_file: | ||
raise ValueError('resolv.conf not found!') | ||
|
||
|
||
def nameserver_regex_check(resolv_file) -> str: | ||
"""return the nameserver ip""" | ||
pattern = re.compile(rb'^\w+\s(?P<nameserver>\d+\.\d+\.\d+\.\d+)$') | ||
nameserver = None | ||
|
||
if resolv_file: | ||
with open(resolv_file[0], 'rb') as r_file: | ||
for line in r_file.readlines(): | ||
match = pattern.match(line) | ||
if match: | ||
nameserver = match.group('nameserver').decode('utf-8') | ||
break | ||
|
||
return nameserver | ||
|
||
|
||
def return_nameserver_ip(nameserver_ip) -> str: | ||
"""Print the nameserver if found""" | ||
if not nameserver_ip: | ||
raise ValueError("Nameserver not found!") | ||
return nameserver_ip | ||
|
||
|
||
def main() -> None: | ||
"""Execute the program""" | ||
resolv_file = check_for_resolv() | ||
list_check(resolv_file) | ||
nameserver_ip_search = nameserver_regex_check(resolv_file) | ||
nameserver_ip = return_nameserver_ip(nameserver_ip_search) | ||
print(nameserver_ip) | ||
|
||
|
||
# Comment out the functions/variables and uncomment | ||
# if __name__ == '__main__' block when using as a standalone script. | ||
|
||
|
||
resolv_file = check_for_resolv() | ||
list_check(resolv_file) | ||
nameserver_ip_search = nameserver_regex_check(resolv_file) | ||
nameserver_ip = return_nameserver_ip(nameserver_ip_search) | ||
print(nameserver_ip) | ||
|
||
|
||
# if __name__ == '__main__': | ||
# main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Nameserver IP | ||
authors: | ||
- name: '0x636f646f' | ||
handle: '@BuildAndDestroy' | ||
link: https://github.com/BuildAndDestroy | ||
description: Retrieve the nameserver IPv4 Address | ||
software: '' | ||
techniques: | ||
- T1016.001 | ||
background: false | ||
output_extension: '' | ||
needs_admin: false | ||
opsec_safe: false | ||
language: python | ||
min_language_version: '3.6' | ||
comments: | ||
- https://attack.mitre.org/techniques/T1016/001/ | ||
options: | ||
- name: Agent | ||
description: Agent to execute module on | ||
required: true | ||
value: '' | ||
script_path: 'python/discovery/nameserver.py' |