Skip to content

Commit

Permalink
Adds Python Meterpreter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Nov 1, 2023
1 parent c073330 commit e6ff953
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions python/meterpreter/tests/test_ext_server_stdapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,26 @@ def test_stdapi_sys_config_getsid(self):
self.assertRegex(sid, "S-1-5-.*")

class ExtStdNetResolveTest(ExtServerStdApiTest):
def stdapi_net_resolve_hosts(self):
def test_stdapi_net_resolve_host(self):
# Full request from msfconsole
request = b'\x00\x00\x00\x0c\x00\x02\x00\x01\x00\x00\x04\x00\x00\x00\x00)\x00\x01\x00\x0264769531726942037539492283558475\x00\x00\x00\x00\x13\x00\x01\x05xrapid7.com\x00\x00\x00\x00\x0c\x00\x02\x05\xa4\x00\x00\x00\x02'
response = bytes()
_result_code, result_tlvs = self.assertMethodErrorSuccess(
"stdapi_net_resolve_hosts", request, response
)

print(response)
resolved_hosts = self.meterpreter_context["packet_get_tlv"](
result_tlvs, self.ext_server_stdapi["TLV_TYPE_RESOLVE_HOST_ENTRY"]
).get("value")

# TODO: Assert
# user_name = self.meterpreter_context["packet_get_tlv"](
# result_tlvs, self.ext_server_stdapi["TLV_TYPE_USER_NAME"]
# ).get("value")
#
#self.assert(response, bytes('......'))
resolved_hosts = self.meterpreter_context["packet_enum_tlvs"](
resolved_hosts, self.ext_server_stdapi["TLV_TYPE_IP"]
)

for host in resolved_hosts:
ip = socket.inet_ntop(socket.AF_INET, host['value'])
# Checks if IP is a valid IP address
self.assertTrue(isinstance(socket.inet_aton(ip), str))

if __name__ == "__main__":
unittest.main()

0 comments on commit e6ff953

Please sign in to comment.