Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Request body extraction #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pcap2har/har.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def HTTPRequestJsonRepr(self):
'''
self = http.Request
'''
content = {
'size': self.body_length,
'mimeType': self.mimeType
}
if self.compression_amount is not None:
content['compression'] = self.compression_amount
if self.text:
if self.encoding:
content['text'] = self.text
content['encoding'] = self.encoding
else:
content['text'] = self.text.encode('utf8') # must transcode to utf-8
# FIXME: should process postData further and replace text
# with params if URL encoded parameters
return {
'method': self.msg.method,
'url': self.url,
Expand All @@ -43,6 +57,7 @@ def HTTPRequestJsonRepr(self):
'headersSize': -1,
'headers': header_json_repr(self.msg.headers),
'bodySize': len(self.msg.body),
'postData': content,
}
http.Request.json_repr = HTTPRequestJsonRepr

Expand Down
22 changes: 21 additions & 1 deletion pcap2har/http/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

# dpkt.http is buggy, so we use our modified replacement
from .. import dpkt_http_replacement as dpkt_http
from .. import settings
from ..mediatype import MediaType
import message as http
from response import Response


class Request(http.Message):
class Request(Response):
'''
HTTP request. Parses higher-level info out of dpkt.http.Request
Members:
Expand All @@ -24,3 +27,20 @@ def __init__(self, tcpdir, pointer):
self.fullurl = fullurl.geturl()
self.url, frag = urlparse.urldefrag(self.fullurl)
self.query = urlparse.parse_qs(uri.query, keep_blank_values=True)

if 'content-type' in self.msg.headers:
self.mediaType = MediaType(self.msg.headers['content-type'])
else:
self.mediaType = MediaType('application/x-unknown-content-type')
self.mimeType = self.mediaType.mimeType()
self.body_length = len(self.msg.body)
self.compression_amount = None
self.text = None
# handle body stuff
if settings.drop_bodies:
self.clear_body()
else:
# uncompress body if necessary
self.handle_compression()
# try to get out unicode
self.handle_text()