1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00
Commit Graph

137 Commits

Author SHA1 Message Date
batrick
148fa94265 whitespace/formatting consistency 2010-04-24 03:29:29 +00:00
batrick
98d4bee8e5 global bug fixes 2010-04-08 20:36:43 +00:00
jah
aec0b2c88c Add nsedoc @return tag for get_url. 2010-04-04 13:00:02 +00:00
ron
dd471d09d5 Fixed a bug in http.lua where http.post() wouldn't work if the arguments were passed in as a string instead of a table (the documentation says it should work in both places) 2010-04-01 04:41:48 +00:00
david
5fa554266b Fix NSEDoc. 2010-03-31 20:28:14 +00:00
david
3510744a54 Canonicalize the formatting of some functions in http.lua. 2010-02-19 05:13:02 +00:00
david
4178846c05 Honor the options table in http.request (specifically options.timeout).
I think this was supposed to work but it was broken.
2010-02-19 05:06:57 +00:00
david
bb2e8c439b Factor out common code for HTTP request building. Replace the two-step
buildGet/buildRequest with a one-step build_request. Provide a new
function generic_request that can do a request for any given method
(get, head, and post are now defined in terms of this function).
2010-02-19 04:54:28 +00:00
david
7f892c1563 Don't pass the cookies table as a parameter, but as a member of the
options table, in http functions. It was unreasonable that this
yet-unused feature was given a more prominent place than even the header
and request body, both of which are in the options table.

This change doesn't affect any other scripts or libraries because none
of them use cookies. In the cases, like http.get, where cookies was an
optional final parameter, I just removed it. Where it was not the final
parameter, as in http.post and http.pGet, I left the parameter in place
but documented that it is ignored for backwards compatibility.
2010-02-19 03:25:57 +00:00
batrick
2038337907 Fixed a global variable being set. I believe the intent was to set
response.body and not result.body.
2010-02-08 02:35:17 +00:00
fyodor
d85c8d3603 Typo fix: reponses -> responses 2010-01-27 02:05:01 +00:00
david
349f0edad0 Let http.next_response receive a body in response to a HEAD request, if
there is one. Even though section 4.4 of RFC 2616 says that sending a
body in response to a HEAD request is a MUST NOT, pyllyukko sent me a
sample from a server that does--"LuCI - Lua Configuration Interface".
2010-01-21 19:42:52 +00:00
david
929042a690 Fix the first round of HTTP pipeline requests. The pipeline makes an
initial request to get a value stored in the Keep-Alive header, which is
the size of the pipeline. It then iterates, doignt hat many requests at
once until the list of requests is exhausted. The prbolem was that in
the first round, it didn't count its initial Keep-Alive probe. So if the
server said it was good for 40 requests, we would send 41 before closing
the connection. Even worse was when the initial probe returned a
"Connection: close"; the pipeline would try another request before
closing the connection for the first time.
2010-01-21 17:43:23 +00:00
david
c7b4af21db o [NSE] Fixed a bug in http.lua that could lead to an assertion
failure. It happened when there was an error getting the a response
  at the beginning of a batch in http.pipeline. The symptoms of the
  bug were:
    NSE: Received only 0 of 1 expected reponses.
    Decreasing max pipelined requests to 0.
    NSOCK (0.1870s) Write request for 0 bytes...
    nmap: nsock_core.c:516: handle_write_result: Assertion `bytesleft > 0' failed.
  The error was reported by Brandon Enright and pyllyukko.
2010-01-21 16:28:39 +00:00
david
d390452e36 Fix a string format error in the HTTP dechunking code. 2010-01-21 00:35:12 +00:00
david
8a895ff0d9 Fix an error with http.request: If there was a parsing error or a
network error, it was returning nil instead of a table as documented.
2010-01-21 00:23:56 +00:00
david
19c2d93903 Merge from /nmap-exp/david/nselib-http. This is an overhaul of HTTP
parsing mostly. Response parsing is centralized, and fewer operations
are done on raw HTTP data.

The biggest user-visible change is that http.request goes back to
returning a parsed result table, not raw HTTP data. I believe this is
how the function worked in the past; it's what the NSEDoc for the
function says. The only thing that used http.request was citrixxml.lua,
and this commit alters it to match the new expectations.

The other change is that the http.pipeline function no longer accepts
the "raw" option. The only script that used that was sql-injection.nse,
and this commit modifies that script as well.
2010-01-13 02:53:13 +00:00
david
f5cae99a2a Check that nmap.registry.args exists before trying to access
nmap.registry.args["http.useragent"]. The args table doesn't exist
during --script-updatedb. The bug was found by Tom Sellers and fixed by
Jah.
2010-01-12 17:53:01 +00:00
david
12203a8ae1 Don't allow a cached response from a GET request to be returned for a
HEAD request. This makes it look like the response to the HEAD request
has a body. As a result, http-enum can wrongly surmise that HEAD
requests don't work when it hits a cache entry while testing HEAD.

# nmap --script=http-date,http-enum -PN -p 80 -d2
NSE: NSE Script Threads (2) running:
NSE: Final http cache size (373 bytes) of max size of 1000000
NSE: HTTP: Host returns proper 404 result.
NSE: Final http cache size (1905 bytes) of max size of 1000000
NSE: Finished 'http-date' (thread: 0x8535a40).
NSE: HTTP: Warning: Host returned data when performing HEAD.
NSE: Checking if a GET request is going to work out

After this change:

NSE: NSE Script Threads (2) running:
NSE: Final http cache size (373 bytes) of max size of 1000000
NSE: HTTP: Host returns proper 404 result.
NSE: Final http cache size (1905 bytes) of max size of 1000000
NSE: Finished 'http-date' (thread: 0x8e75b00).
NSE: Final http cache size (1905 bytes) of max size of 1000000
NSE: HTTP: Host supports HEAD.
2010-01-10 19:47:33 +00:00
david
d38ef0da41 Change the header name from "Cookies" to "Cookie" in http.lua. "Cookies"
is incorrect; see RFC 2109 section 4.3.4.
2010-01-09 22:54:37 +00:00
david
d6f8e9edda Merge r16415:16416 from /nmap-exp/david/nselib-http. I meant to do those
commits here in the first place.
2010-01-08 01:13:24 +00:00
david
ee0fee26c0 Skip over a single 100 Continue response, if present, before parsing the
real response in http.lua. This patch is by Patrik Karlsson.
2009-12-13 22:52:08 +00:00
david
315e6ef9b0 Remove a debugging statement from http.lua. 2009-12-13 01:51:05 +00:00
david
5eca175a11 Don't encode a POST body and set the content-type
application/x-www-form-urlencoded if the body is a string. Only do it
when the body is a table, meaning we want to do a form submission.
2009-12-13 01:50:26 +00:00
david
5cc9d5249a In http.lua, add the port number to the value of the Host header field
when the number is not 80. See RFC 2616, section 14.23. This was
suggested by Tom Sellers.
2009-11-09 20:26:55 +00:00
joao
4c13b99e95 Giving priority to transfer-encoding first than content-length, as mentioned in rfc2616, section 4.4.
isChunked now checks for transfer-encoding: identity instead of transfer-encoding: chunked. If transfer encoding is present and it is not identity, chunked encoding is considered. Also rfc2616, section 4.4 (item 2)
2009-09-15 03:47:46 +00:00
joao
b9d1591739 Adding a few comments on some functions 2009-09-15 02:46:58 +00:00
joao
b0346e22b9 Fixing problem related to chunked pipelined responses on http.lua 2009-09-15 02:12:02 +00:00
ron
537726defa Added '503 Service Unavailable' to the list of recognized error codes for 404 errors. I observed this on a 'Microsoft Project Server' host that gave valid results (though odd 404s). I also changed the code such that the scan will still run, even if an unrecognized error code is encountered. 2009-09-02 14:12:03 +00:00
ron
4564ed7503 Added '400' as a potential 404 page. Ran into this while scanning a Fortigate device. 2009-09-01 19:23:17 +00:00
ron
7da313e8ac Added the status code to the rawheaders as well (so it's displayed in http-headers.nse). Also updated the @output in the nsedoc. 2009-08-27 15:47:10 +00:00
ron
62dedb9dc1 Added a 'path' script-arg to http-headers.nse. Changed it to use 'HEAD' by default, and fail to using 'GET' the same way other scripts do (also added a 'useget' script-arg to turn it off). Also fixed some print_debugs in http.lua that were prefixed with 'http-enum.nse:'. 2009-08-27 15:39:17 +00:00
ron
fc2b575fba Added 'rawheader' when parsing http requests. It saves the header fields, in order, preserving the case. Change http-headers.nse to read this instead of the processed headers. 2009-08-27 15:24:09 +00:00
ron
46711fa004 Fixed a big in the http library that cropped up while scanning multiple hosts at the same ip address. The reason this occurred is because the result would be cached based on the ip address, not the target name, so different vhosts on the same ip address would be considered the same by the cache. 2009-08-26 16:01:00 +00:00
ron
986ba5ab8c Realized the my check_get() function was elminating perfectly good hosts. Some of our printers use a '301 Moved Permanently' to redirect you to their login page from the root page, but my script was mistaking those for an off-site redirect. I changed check_get() to display a warning rather than causing the scan to fail. 2009-08-24 19:56:52 +00:00
ron
a02756a5e4 Adding a fix for false positives discovered in http-enum.nse and http-userdir-enum.nse. It seems that some hosts (or, at least, one host) returns different results for:
a) Lowercase path (a login page)
b) Paths containing uppercase (becomes a '400 Unknown Error' that indicates a corrupt harddrive)
c) Paths containing a path and no uppercase (the same login page as (a) is displayed, except the font changes colour
The server itself returns that it's 'ACOS HTTPD/1.1.4', and the telnet port says it's 'Lingo VoIP config telnetd'. OS guesses seem to indicate a Telephony device of some sort. In any case, this patch detects these conditions and doesn't bother checking the device if it cannot tell these errors apart
2009-08-24 03:42:01 +00:00
ron
a46298dcc2 Added a script-arg to http.lua: pipeline. Setting pipeline lets you artificially increase/lower pipelining. The primary reason I added it is because sorting through packet captures with a hundred requests pipelined is difficult, so now I can lower it for debugging. I suggest using '--script-args=pipeline=1,limit=5' if troubleshooting issues with http-enum.nse. 2009-08-24 03:26:01 +00:00
batrick
600ec30c9f [NSE] The HTTP Library now caches responses generated from http.get or
http.head (in revision . Because many scripts tend to request the same object,
this helps to prevent sending duplicate requests that consume network
resources needlessly.

The cache is transparent to the script writer in that it will return a cached
result if present when http.get/http.head is called. How the cache is used may
be controlled by options table (described in [1]) passed to the http functions.

Three new boolean values are present:
  o bypass_cache -- The contents of the cache is ignored for the request
                    (method == "GET" or "HEAD")
  o no_cache -- The result of the request is not saved in the cache
                (method == "GET" or "HEAD")
  o no_cache_body -- The body of the request is not saved in the cache
                     (method == "GET" or "HEAD")

The size of the cache is by default 1 MB. The size can be changed using the
script arg (--script-args) http-max-cache-size (e.g. --script-args
http-max-cache-size=1e8).

[1] http://nmap.org/nsedoc/lib/http.html#request
2009-08-24 01:15:28 +00:00
ron
fbf2c3d6a7 Print the http status along with the result, if it isn't 200 OK. This was the original behaviour, but it got lost along the way. 2009-08-23 16:58:53 +00:00
ron
f8e2fe6429 Added a check for a blank body, due to some false positives I found during a random scan 2009-08-23 04:11:04 +00:00
ron
fbc8e180ca Converted http-userdir-enum.nse to use my http-enum.nse logic (from http.lua). Also moved the 'displayall' script-arg back into the script, not http.lua, because http-userdir-enum.nse actually wants to find non-200 pages (403 Access Denied, for instance). 2009-08-23 00:43:46 +00:00
ron
cf33de55f3 Moved the definition for the 'displayall' argument into http.lua. 2009-08-23 00:24:23 +00:00
ron
77e7738545 Moved the meat of the http-enum.nse code (the 404-detection, HEAD-detection, etc) into http.lua. It may be a better idea to use http-helper.lua or something similar, but for now http.lua works. I'm open to suggestiosn. 2009-08-23 00:22:20 +00:00
ron
393110baf1 Fixed a bug where http.pipeline() would print a cryptic error if no requests were passed for it to perform. Changed it to print a warning if debugging is turned on, and return an empty set. 2009-08-22 22:23:03 +00:00
ron
08073b43b8 Fix two bugs in the http libraries:
1) Re-add 443 to the common ssl ports (it was accidentally removed in an earlier patch)
2) If the header doesn't return the number of pipelined requests to perform, default to 40 instead of leaving it nil
2009-08-21 23:42:07 +00:00
joao
2264838cf8 Fixed bug where socket error messages (like EOF) were appended to the HTTP pipeline response 2009-08-20 03:12:54 +00:00
ron
f2ed53ebfc Removed an undeclared variable in http.lua. 2009-08-18 02:20:33 +00:00
ron
6aee1ce91c Fixed a spelling mistake in http.lua. 2009-08-18 01:40:33 +00:00
batrick
d5748b1d83 If the response is already a table (from an error in http.request) then do not
try to parse a result, instead return nil.  This fixes an error where we try to
index match as though response is a string.
2009-08-15 14:53:28 +00:00
joao
a2dcbb7cd5 Fixing a bug where getPipelineMax was not returning any value, when it sould, at least, return 1. 2009-08-15 14:32:17 +00:00