Sunday, June 7, 2009

Improved Command Line API for jsunpack

A few weeks ago Jesse wrote an excellent script which is a command line interface for jsunpack.

Last week, one reader made some great improvements to this script by allowing you to upload a local file for decoding. It checks each command line argument to see if a local file exists, then if it does it uploads it. Otherwise, it works in the same way as Jesse's original script and just decodes URLs.


#!/usr/bin/perl

use strict;
use CGI;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request::Common;

my $ua = LWP::UserAgent->new;
$ua->agent("jsunpack");

for my $url (@ARGV){
if (-f "$url"){
if(open(FIN, "< $url")){
$url = <FIN>;
close(FIN);
}
else {
print "warning: ignoring '$url', cannot open file\n";
}
}

my $res = $ua->post(
'http://jsunpack.jeek.org/dec/api',
Content_Type => 'application/x-www-form-urlencoded',
Content =>
[
'url' => [$url],
'apikey' => ['exploitme']
]
);

if ($res->is_success){
print $res->content;
}
else {
print "\n\n"."Failed to fetch remote file"."\n\n";
print "jsunpack"."\n".$res->status_line, "\n";
}
}

No comments:

Post a Comment