├── README ├── parse.php └── webparse.php /README: -------------------------------------------------------------------------------- 1 | /*********************************\ 2 | HTTP Parse 3 | A minimal HTTP parsing tool. 4 | Written by Twitch 5 | \*********************************/ 6 | 7 | This was originally designed as part of a Web Application Mapping framework project that I joined. The project, as so many do, withered and died. I may well port this to a more broadly used language or build upon it at a later date, though. -------------------------------------------------------------------------------- /parse.php: -------------------------------------------------------------------------------- 1 | $lv) { 54 | if($lin == "0") { 55 | preg_match("/(HTTP\/...) ([0-9]{3}) (.*)/", $lv, $rsline); 56 | $header["response"] = $rsline; 57 | } else { 58 | preg_match("/^([A-Za-z0-9-]*):(.*)/", $lv, $hname); 59 | $header[$hname[1]] = $hname[2]; 60 | } 61 | } 62 | 63 | return $header; 64 | 65 | // Return values: 66 | // This will return an associative array using the header names for 67 | // associative indecies. 68 | // There is also a special array 'response' which contains the first 69 | // line of the response. The sub elements of this are then broken further. 70 | 71 | // ["response"] 72 | // - [1] = "HTTP/1.1" 73 | // - [2] = "200" 74 | // - [3] = "OK" 75 | } 76 | 77 | if(isset($argv[1])) { 78 | $host = $argv[1]; 79 | } else { 80 | $host = "localhost"; 81 | } 82 | if(isset($argv[2])) { 83 | $port = $argv[2]; 84 | } else { 85 | $port = "80"; 86 | } 87 | if(isset($argv[3])) { 88 | $path = $argv[3]; 89 | } else { 90 | $path = "/"; 91 | } 92 | 93 | 94 | $header = get_heads($host, $port, $path); 95 | 96 | 97 | 98 | 99 | echo $header["response"][1]; 100 | echo " ".$header["response"][2]; 101 | echo " ".$header["response"][3]."\n"; 102 | 103 | foreach($header As $header_name => $header_value) { 104 | if($header_name == "response") { 105 | } else { 106 | echo "$header_name:$header_value\n"; 107 | } 108 | } 109 | 110 | preg_match("/([A-Za-z0-9\=\-\:]*);/", $header["Set-Cookie"], $ck); 111 | echo $ck[1]."\n"; 112 | $cookies = explode(":", $header["Set-Cookie"]); 113 | 114 | //var_dump($cookies); 115 | 116 | ?> 117 | -------------------------------------------------------------------------------- /webparse.php: -------------------------------------------------------------------------------- 1 | $lv) { 60 | if($lin == "0") { 61 | preg_match("/(HTTP\/...) ([0-9]{3}) (.*)/", $lv, $rsline); 62 | $header["response"] = $rsline; 63 | } else { 64 | preg_match("/^([A-Za-z0-9-]*):(.*)/", $lv, $hname); 65 | $header[$hname[1]] = $hname[2]; 66 | } 67 | } 68 | $header["q"] = $q; 69 | return $header; 70 | 71 | // Return values: 72 | // This will return an associative array using the header names for 73 | // associative indecies. 74 | // There is also a special array 'response' which contains the first 75 | // line of the response. The sub elements of this are then broken further. 76 | 77 | // ["response"] 78 | // - [1] = "HTTP/1.1" 79 | // - [2] = "200" 80 | // - [3] = "OK" 81 | } 82 | 83 | // Build an array of methods, even though some aren't fully supported by most servers. 84 | // This will make it easier to add/remove these as needed. 85 | $methods = array( 86 | "GET", 87 | "POST", 88 | "HEAD", 89 | "OPTIONS", 90 | "PUT", 91 | "DELETE", 92 | "TRACE", 93 | "CONNECT" 94 | ); 95 | 96 | // Build our request form now. 97 | 98 | ?> 99 | 100 | 101 | 102 | Request Building / Testing Engine 103 | 104 | 105 | 106 | 107 |
108 | 109 |
" method="POST"> 110 | 111 | 112 | 113 | 114 | 115 | 134 | 135 | 136 | 139 | 140 | 141 | 142 | 143 |
Host:
">
116 | 125 | 126 | "> 127 | 128 | 133 |
137 | 138 |
144 |
145 |
146 | 147 |
148 | $newq"; 165 | 166 | // Let's set an array so we can change the colors based on the type of status code. 167 | // Nifty. 168 | $bgs = array( 169 | "1" => "6dafe1", 170 | "2" => "6dafe1", 171 | "3" => "d3b87f", 172 | "4" => "d27777", 173 | "5" => "fc5555" 174 | ); 175 | 176 | echo "
"; 177 | echo "
"; 178 | 179 | echo ""; 180 | echo $header["response"][1]." ".$header["response"][2]." ".$header["response"][3]."

"; 181 | echo ""; 182 | 183 | // This is sort of confusing. I needed to reference the actual response line 184 | // and wanted to be able to print out the query, as well. To do this, though 185 | // I needed to pass them in the return value. So we have to make sure we don't 186 | // confuse these for being headers. 187 | // 188 | // Excluding the query and response, let's spit out the headers. 189 | 190 | 191 | foreach($header As $header_name => $header_value) { 192 | if($header_name == "response" || $header_name == "q") { 193 | } else { 194 | echo "$header_name:$header_value
"; 195 | } 196 | } 197 | 198 | // I believe I was aiming to set variables for each cookie here, or something. 199 | // Honestly I don't recall. I'll update if I do. =/ 200 | preg_match("/([A-Za-z0-9\=\-\:]*);/", $header["Set-Cookie"], $ck); 201 | echo $ck[1]."\n"; 202 | $cookies = explode(":", $header["Set-Cookie"]); 203 | 204 | } 205 | 206 | 207 | ?> 208 | 209 |

210 | 211 | 212 | 213 | --------------------------------------------------------------------------------