// Command mapscan v1.0
if params.len != 1 or params[0] == "-h" or params[0] == "--help" then exit("Usage: "+program_path.split("/")[-1]+" [ip_address]")
metax = include_lib("/lib/metaxploit.so")
if not metax then exit("Error: Unable to find 'metaxploit.so'. Put missing library in the 'lib' folder.")
shell = get_shell
computer = shell.host_computer
if not is_valid_ip(params[0]) then exit("nmap: invalid ip address")
if not computer.is_network_active then exit("nmap: No internet access.")
ipAddress = params[0]
if ipAddress == "127.0.0.1" then ipAddress = computer.local_ip
isLanIp = is_lan_ip( ipAddress )
if isLanIp then
router = get_router;
else
router = get_router( ipAddress )
end if
if router == null then exit("nmap: ip address not found")
ports = null
if not isLanIp then
ports = router.used_ports
else
ports = router.device_ports(ipAddress)
end if
if ports == null then exit("nmap: ip address not found")
if typeof(ports) == "string" then exit(ports)
targetsFolderName = "Targets"
targetsFolderPath = "/home/"+active_user
targetsFolder = targetsFolderPath + "/" + targetsFolderName
if computer.File(targetsFolder) == null then computer.create_folder(targetsFolderPath, targetsFolderName)
outputFile = computer.File(targetsFolder + "/" + ipAddress + ".txt")
if outputFile == null then
computer.touch(targetsFolder, ipAddress + ".txt")
outputFile = computer.File(targetsFolder + "/" + ipAddress + ".txt")
end if
output = ""
info = "PORT STATE SERVICE VERSION LAN"
print("\nStarting nmap v2.0 at " + current_date)
print("Interesting ports on " + params[0] + "\n")
if(ports.len == 0) then exit("Scan finished. No open ports.")
for port in ports
service_info = router.port_info(port)
lan_ips = port.get_lan_ip
port_status = "open"
if(port.is_closed and not isLanIp) then
port_status = "closed"
end if
info = info + "\n" + port.port_number + " " + port_status + " " + service_info + " " + lan_ips
end for
print(format_columns(info) + "\n")
output = output + format_columns(info) + char(10)
for port in ports
net_session = metax.net_use(ipAddress, port.port_number)
if not net_session then exit("Error: Unable to connect.")
metaLib = net_session.dump_lib
print("\nScanning " + metaLib.lib_name + " v" + metaLib.version + " on port " + port.port_number)
output = output + char(10) + char(10) + "Scanned " + metaLib.lib_name + " v" + metaLib.version + " on port " + port.port_number
scanResult = metax.scan(metaLib)
for zone in scanResult
memory_scan = metax.scan_address(metaLib, zone)
print("\nFound memory zone: " + zone)
output = output + char(10) + char(10) + "Exploits for zone: " + zone
xpList = memory_scan.split("Unsafe check: ")[1:]
exploits = []
for xp in xpList
labelStart = xp.indexOf("")
labelEnd = xp.indexOf("")
exploits.push(xp[labelStart + 3: labelEnd])
end for
print("Available vulnerabilities: " + exploits.join(", "))
output = output + char(10) + "Vulnerabilities found: " + exploits.join(char(10))
end for
end for
outputFile.set_content(output)
print ("\nNMAP Scan completed.\nResults saved to " + ipAddress + ".txt in " + targetsFolderName + " folder.")