fake nessus

This commit is contained in:
Brendan McDevitt 2020-07-20 16:31:10 -05:00
parent 60a9afeb06
commit 72967f25b9

View file

@ -11,26 +11,30 @@ class FakeTunnelConnector
def listen_and_respond
tcp_socket = server.accept
read_socket(tcp_socket)
write_response(tcp_socket)
response = read_socket(tcp_socket)
location = response[:start_line][:location]
write_response(tcp_socket, location)
tcp_socket.close
end
def read_socket(tcp_socket)
headers = []
start_line = []
headers = []
puts "Request Incoming:"
puts "-------------------"
# read lines from socket
while (line = tcp_socket.gets) && (line.chomp.length > 0)
# check for a valid http verb sent
puts parse_http_start_request_line(line) if Http::METHODS.include?(line.split.first)
start_line = parse_http_start_request_line(line) if Http::METHODS.include?(line.split.first)
header_line = parse_http_header_request_line(line)
headers << header_line unless header_line.nil?
end
puts start_line
puts "Request Headers:"
puts "-------------------"
puts headers
puts "\r\n"
{:start_line => start_line, :headers => headers}
end
def parse_http_start_request_line(line)
@ -58,11 +62,35 @@ class FakeTunnelConnector
end
end
def write_response(tcp_socket)
tcp_socket.sendmsg(ok)
def write_response(tcp_socket, location)
route_response_string = route_request(location)
tcp_socket.sendmsg(ok(route_response_string))
end
def ok
"HTTP/1.1 200 OK\r\nDate: #{Time.now.utc}\r\n\r\nSuccess!\r\n"
def ok(body='Success')
"HTTP/1.1 200 OK\r\nDate: #{Time.now.utc}\r\n\r\n#{body}\r\n"
end
def route_request(location)
if location == '/scans'
scans
elsif location == '/login'
login
else
ok
end
end
def scans
body = '{"folders":[{"unread_count":0,"custom":0,"default_tag":0,"type":"trash","name":"Trash","id":7},{"unread_count":0,"custom":0,"default_tag":1,"type":"main","name":"My
Scans","id":8}],"scans":[{"legacy":false,"permissions":128,"type":"remote","read":true,"last_modification_date":1535393942,"creation_date":1535393789,"status":"completed","uuid":"71e19d73-6308-42b0-adee-b26c9ddabfda","shared":false,"user_permissions":128,"owner":"edbellis","schedule_uuid":"template-7f64b006-dfaf-feee-85bd-ea9dd47280cf3a9573b1fc8089e7","timezone":null,"rrules":null,"starttime":null,"enabled":false,"control":true,"name":"Kenna
Security: Nessus API (ON PREM YO)","id":29}],"timestamp":1535395026}'
ok(body)
end
def login
body = '{"token":"797118d801342a0c5c5be3ed5420782becbea2e3bceea9275543dff4ee62dfc4"}'
ok(body)
end
end