Code Monkey home page Code Monkey logo

harx's Introduction

Description

HAR eXtractor.

This utility was developed to assist security analysts working with HTTP Archive (HAR) files to list and extract the contained objects.

More information about the HTTP Archive (HAR) format can be read here: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html

Disclaimer

  • This code is a proof of concept only and is not warranted for production use
  • No support is available for this software
  • This code has not been audited for security issues
  • Use entirely at your own risk

Requirements

Python 2.7

  • Python Magic Module: pip install python-magic

For quick module installation:

pip install -r requirements.txt

Usage

usage: harx.py [-h] [-c CSV] [-l] [-x EXTRACT] [-xa] [-d DIRECTORY] har_file

positional arguments:
  har_file

optional arguments:
  -h, --help            show this help message and exit
  -c CSV, --csv CSV     Save object list to [CSV]
  -l, --list            List objects
  -x EXTRACT, --eXtract EXTRACT
                        eXtract object matching index from -l output
  -xa, --eXtractAll     eXtract all objects
  -d DIRECTORY, --directory DIRECTORY
                        [DIRECTORY] to extract files to

Example Execution

List objects

./harx.py -l ek_traffic.har
[  0] [2015-08-31T17:56:12.104071Z] [   GET] [                    text/plain] [Size:       14] [http://www.msftncsi.com/ncsi.txt]
[  1] [2015-08-31T17:56:46.994169Z] [   GET] [                     text/html] [Size:     1305] [http://api.bing.com/qsml.aspx?query=go&maxwidth=32765&rowheight=20&sectionHeight=160&FORM=IESS02&market=en-US]
[  2] [2015-08-31T17:56:47.544066Z] [   GET] [                     text/html] [Size:     1346] [http://api.bing.com/qsml.aspx?query=google&maxwidth=32765&rowheight=20&sectionHeight=160&FORM=IESS02&market=en-US]
[  3] [2015-08-31T17:56:47.807992Z] [   GET] [                     text/html] [Size:     1369] [http://api.bing.com/qsml.aspx?query=google.c&maxwidth=32765&rowheight=20&sectionHeight=160&FORM=IESS02&market=en-US]
...
[209] [2015-08-31T18:01:22.238266Z] [  POST] [     application/ocsp-response] [Size:     1336] [http://gtssl-ocsp.geotrust.com/]
[210] [2015-08-31T18:01:23.122156Z] [  POST] [     application/ocsp-response] [Size:     1453] [http://ocsp.verisign.com/]
[211] [2015-08-31T18:01:23.248269Z] [  POST] [     application/ocsp-response] [Size:     1762] [http://ocsp.verisign.com/]
[212] [2015-08-31T18:01:23.442410Z] [  POST] [     application/ocsp-response] [Size:     1725] [http://sf.symcd.com/]

Extract object matching index from -l output

./harx.py -x 137 ek_traffic.har
[137] [       41keG5PBKbL-274x300.jpg] [Size:  32.5KiB] [3b58d7efe887212e2b1b631bdd417034] [                    image/jpeg] [http://example.com/wp-content/uploads/2015/06/41keG5PBKbL-274x300.jpg]

Extract all objects to a folder

./harx.py -xa -d ek_traffic_analysis ek_traffic.har
[  0] [                      ncsi.txt] [Size:    14.0B] [cd5a4d3fdd5bffc16bf959ef75cf37bc] [                    text/plain] [http://www.msftncsi.com/ncsi.txt]
[  1] [                     qsml.aspx] [Size:   110.0B] [b0c846fc56e41d5eec6adf8e92a59fef] [      application/octet-stream] [http://api.bing.com/qsml.aspx?query=go&maxwidth=32765&rowheight=20&sectionHeight=160&FORM=IESS02&market=en-US]
[  2] [                     qsml.aspx] [Size:   113.0B] [e78f910e1a340736b2e5e81aea8d0880] [      application/octet-stream] [http://api.bing.com/qsml.aspx?query=google&maxwidth=32765&rowheight=20&sectionHeight=160&FORM=IESS02&market=en-US]
[  3] [                     qsml.aspx] [Size:   128.0B] [307f529a949ee293872b226dd7c2668c] [      application/octet-stream] [http://api.bing.com/qsml.aspx?query=google.c&maxwidth=32765&rowheight=20&sectionHeight=160&FORM=IESS02&market=en-US]
...
[209] [  gtssl-ocsp.geotrust.com.file] [Size:   1.3KiB] [09a6f239fd0bd44d43a739b64253057b] [      application/octet-stream] [http://gtssl-ocsp.geotrust.com/]
[210] [        ocsp.verisign.com.file] [Size:   1.4KiB] [45f667114e55de8ee7c8bfc0bb0e7744] [      application/octet-stream] [http://ocsp.verisign.com/]
[211] [        ocsp.verisign.com.file] [Size:   1.7KiB] [eadb300a3afed5b2cb378cbb8548386a] [      application/octet-stream] [http://ocsp.verisign.com/]
[212] [             sf.symcd.com.file] [Size:   1.7KiB] [516235e7ad11627ed89b9b8248ee89b7] [      application/octet-stream] [http://sf.symcd.com/]

harx's People

Contributors

morsch avatar ruanmuller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

harx's Issues

My use case

Hello,

First of all, I'd like to say that this is a great little script which helped me a lot on my current project. Would love to see it starred more.

I have a couple of suggestions, fixes that I had to make to make it work the way I wanted.

By default this script exports everything in one folder when using -xa flag, which is useful in some cases, but not when you're trying to see the structure of a webpage or something similar. Therefore I needed to add folder support, so that every resource that is located in the HAR file is exported to its folder according to original path.

Second thing I noticed was that some of the plain text files (json, js, txt, etc.) were incorrectly exported, meaning they'd be binary garbled files, which was happening because getB64Decode method was being called on all of the resources regardless of its type.

So I changed the processObject method to look like this:

def processObject(idx, content, filename, path):
    """Common Object Processing"""

    f = re.sub(r'https?:\/\/', '', re.sub(r'\?.*', '', filename))
    dest = path + f

    if not os.path.exists(os.path.dirname(dest)):
        os.makedirs(os.path.dirname(dest))

    if dest.endswith('/'):
        dest = dest + 'index.html'
    
    data = content
    smth, ext = os.path.splitext(dest)
    if not (ext.endswith('json') or ext.endswith('js') or ext.endswith('asp') or ext.endswith('aspx') or ext.endswith('txt') or ext.endswith('css')):
        data = getB64Decode(content)

    writeFile(dest, data)
    md5 = getMD5(dest)
    size = getSize(dest)
    mime = getMagic(dest)

    print "[" + str(idx).rjust(3, " ") + "] " +\
    	"[" + f[0:30].rjust(30, " ") + "] " +\
    	"[Size: " + size.rjust(8, " ") + "] "+\
    	"[" + md5 + "] [" + mime.rjust(30, " ") + "] " +\
    	"[" + objectList[idx]['url'] + "]"

    return True

This helped me resolve all of the issues I had. Hope this helps somebody in the future. Please note that this is the first time I ever touched Python code, so it may not look great.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.