#!/usr/bin/perl## Script for posting command's output directly from command line.## i wrote this script to be able use it on solaris operating system without## installing any exotic or not core perl modules (.pm)#### script has just one dependency: wget knowing option --post-file= ..#### This script is written in "compat" way, so as mentioned above, no additional .pms## are used, so this script should work almost everywhere with perl.#### author: dpecka[at]opensuse[dot]org## enjoy !!#### TODO: add support for alternative pastebin server.#### This Software is released under: 3-clause license ("New BSD License") #### Copyright (c) 2010, Daniel Pecka## All rights reserved.#### Redistribution and use in source and binary forms, with or without## modification, are permitted provided that the following conditions are met:## * Redistributions of source code must retain the above copyright## notice, this list of conditions and the following disclaimer.## * Redistributions in binary form must reproduce the above copyright## notice, this list of conditions and the following disclaimer in the## documentation and/or other materials provided with the distribution.## * Neither the name of the organization nor the## names of its contributors may be used to endorse or promote products## derived from this software without specific prior written permission.#### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE## DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY## DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES## (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.##use strict;use warnings;sub version { print STDERR << 'EOF';Version: 0.9.3 (2010-12-28)EOF exit 0;};sub usage { print STDERR << 'EOF';Usage: foo | pastebin.pl [-fr] [-t type] [-d description] [-e expiration] [-n name]-f exploit pastebin.ca even if input has less then 5 lines-r prints out link to raw format-t expects one from types listed below-d short paste description-e expire in time, default is "never", you can choose from list below (m=minutes,h=hours ..)-n alternate nick, default is your $USER enviroment variable-h this help message thrown to /dev/stderr and exits-v prints out version on /dev/stderr and exitsescape white characters in name and description string ..Types: action ada apache asm asp asterisk bash c c# c++ css delphi diff html java javascript lisp lua mirc nasm net objc pascal patch perl php pli python raw ruby scheme sql vbs xmlExpire: 5m 10m 15m 30m 45m 1h 2h 4h 8h 12h 1d 2d 3d 1w 2w 3w 1mn 2mn 3mn 4mn 5mn 6mn 1yEOF exit 2;};## several checks .. we need to know if we have sufficient wgetmy $wpath;sub checks { chomp($wpath = `which wget 2>/dev/null`); die "can't find wget within your \$PATH, it's over ..\n" if ! -x "$wpath"; chomp(my $winfo = `$wpath --help | grep post-file=`); die "it seems like your wget has not option --post-file=, it's over ..\n" if ! "$winfo";};## parses cli and assigns a base varsmy($pforc, $praw, $ptype, $pdesc, $pexpi, $puser);$pforc = "false";$praw = "false";$ptype = 33;$pdesc = "";$pexpi = "";$puser = $ENV{"USER"};sub parse_cli { return 0 if ! @ARGV; while(@ARGV) { $_ = shift(@ARGV); if(/^(-fr|-rf)$/) { unshift(@ARGV, "-f"); unshift(@ARGV, "-r"); next; }; if(/^-f$/) { $pforc="true"; next; }; if(/^-r$/) { $praw="true"; next; }; if(/^-t$/) { $ptype = shift(@ARGV); $ptype =~ y/[A-Z]/[a-z]/; my %types = ( raw => "1", asterisk => "2", c => "3", "c++" => "4", php => "5", perl => "6", java => "7", vbs => "8", "c#" => "9", ruby => "10", python => "11", pascal => "12", mirc => "13", pli => "14", xml => "15", sql => "16", scheme => "17", action => "18", ada => "19", apache => "20", nasm => "21", asp => "22", bash => "23", css => "24", delphi => "25", html => "26", javascript => "27", lisp => "28", lua => "29", asm => "30", objc => "31", net => "32", diff => "33", patch => "33", ); if(!grep(/^$ptype$/, keys(%types))) { print STDERR "bad type: $ptype\n"; die "choose one from: ", join(" ", sort(keys(%types))), "\n"; }; $ptype = $types{"$ptype"}; next; }; if(/^-d$/) { $pdesc = shift(@ARGV); $pdesc =~ s/%/%25/g; $pdesc =~ s/&/%26/g; $pdesc =~ s/\+/%2B/g; next; }; if(/^-e$/) { $pexpi = shift(@ARGV); $pexpi =~ y/[A-Z]/[a-z]/; my %expires = ( m5 => "5 minutes", m01 => "10 minutes", m51 => "15 minutes", m03 => "30 minutes", m54 => "45 minutes", h1 => "1 hour", h2 => "2 hours", h4 => "4 hours", h8 => "8 hours", h21 => "12 hours", d1 => "1 day", d2 => "2 days", d3 => "3 days", w1 => "1 week", w2 => "2 weeks", w3 => "3 weeks", nm1 => "1 month", nm2 => "2 months", nm3 => "3 months", nm4 => "4 months", nm5 => "5 months", nm6 => "6 months", y1 => "1 year", ); my $pexpi_tmp = scalar(reverse($pexpi)); if(!grep(/^$pexpi_tmp$/, keys(%expires))) { print STDERR "bad expiration time: $pexpi\n"; die "choose one from: 5m 10m 15m 30m 45m 1h 2h 4h 8h 12h 1d 2d 3d 1w 2w 3w 1mn 2mn 3mn 4mn 5mn 6mn 1y\n"; }; $pexpi = $expires{"$pexpi_tmp"}; next; }; if(/^-n$/) { $puser=shift(@ARGV); next; }; usage() if(/^(-h|--help)$/); version() if(/^-(v|V|-version)$/); print STDERR "bad option: $_\n"; usage(); };};## build and upload tmp file ..sub build_upload_file { my $pfile; my $plines = 0; open($pfile, ">", "/tmp/pastebin.pl.tmp"); print $pfile "name=$puser&type=$ptype&description=$pdesc&expiry=$pexpi&s=Submit+Post&content="; while(<>) { s/%/%25/g; s/&/%26/g; s/\+/%2B/g; print $pfile "$_"; $plines += 1; }; close($pfile); die "input is shorter then 5 lines, use -f option to force exploit pastebin.ca\n" if(($plines < 5) && $pforc !~ /^true$/);};my $pastebinkey = "4g64jruLaAtRJt8XvjDn1Qt3jsQTgCmx";sub upload_file { chomp(my @wget_output = `$wpath -O - --tries=5 --timeout=60 --post-file=/tmp/pastebin.pl.tmp http://pastebin.ca/quiet-paste.php?api=$pastebinkey 2>&1`); foreach(@wget_output) { next if ! /SUCCESS:/; my $link="$_\n" if s#^.*:([0-9][0-9]*).*#http://pastebin.ca/$1#; $link =~ s@/(\w+)$@/raw/$1@ if($praw !~ /^false$/); print "$link" if $link; return 0; }; die "can't post at pastebin.ca:\n@wget_output\n";};### Body from here:checks();parse_cli();build_upload_file();upload_file();unlink "/tmp/pastebin.pl.tmp";#print << "EOF";#pforce: $pforc#ptype: $ptype#pdesc: $pdesc#pexpi: $pexpi#puser: $puser#EOFexit 0;