Randomsprunge

Stato
Discussione chiusa ad ulteriori risposte.

EvilMau

Utente Silver
25 Gennaio 2011
8
1
0
51
Ecco il testo del esercizio:
Codice:
Scrivere un programma che trovi file su sprunge.us in maniera casuale :3

ecco il mio:
Codice:
require 'net/http'
$a = [] and (26).times {|x|
	$a << (65+x).chr
} and (26).times {|x|
	$a << (97+x).chr
}
$c = 0
def test(x)
	buff = ""
	4.times do
		buff = buff + $a[rand($a.size)]
	end
	print "[+] Try /#{buff}\n"
	http = Net::HTTP.new('sprunge.us')
	data = http.get("/#{buff}")
	if data.body != "#{buff} not found"
		puts "Found => #{buff}\nFound after #{x} times..."
		exit
	end
end
while true
	Thread.new do
		$c += 1
		test($c)
	end
end
http://sprunge.us/RIMd?rb

=)
EDIT: WTF? colpo di culo?
Codice:
evilmau@EviLMau-netbook:~/prog/Ruby$ ruby sprungerandom.rb 
[+] Try /RIMd
Found  => RIMd
Found after 1 times...
evilmau@EviLMau-netbook:~/prog/Ruby$
 
In Python:
Codice:
import string
import urllib2
import random

def sprunge():
    t = 1
    while True:
        g = ''.join(random.choice(string.letters) for _ in xrange(4))
        print '[+] Try: /{0}'.format(g)
        content = urllib2.urlopen('http://sprunge.us/{0}'.format(g)).read()
        if content != '{0} not found'.format(g):
            print 'Found => {0}'.format(g)
            print 'Found after {0} iterations'.format(t)
            return
        t += 1
 
Ecco il mio (senza troppi array perché mi scocciavo)
Codice:
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;

my $l = "abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
my $word;
our @found;
$SIG{"INT"} = sub {
	print "\nFound: " . join (", ", @found) . "\n";
	exit;
};
while (1) {
	$word .= substr ($l, int (rand (length ($l))), 1) for (1..4);
	my $tmp;
	print ( ( $tmp = get ("http://sprunge.us/${word}") ) eq "${word} not found" ? "[-] http://sprunge.us/${word} not found.\n" : "[+] http://sprunge.us/${word} found! Trying another..\n" );
	push @found, "http://sprunge.us/${word}" if $tmp ne "${word} not found";
	$word = "";
	sleep (1);
}
http://sprunge.us/dJbb?pl
 
Codice:
require 'net/http'
a="...."
cnt=0
I = ((?a..?z).to_a + (?A..?Z).to_a + (?0..?9).to_a).flatten

begin
	4.times {|i| a[i]=I[rand(I.size)].chr} and cnt+=1
	puts "provo #{a}"
end while Net::HTTP.get(URI.parse("http://sprunge.us/"+a)) == a+" not found"

puts "trovato #{a} dopo #{cnt.to_s} tentativi"

shura: ti ho rubato l'alfabeto
 
fix'd
Codice:
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;

my $l = "abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
my $word;
our @found;
$SIG{"INT"} = sub {
    print "\nFound: " . join (", ", @found) . "\n";
    exit;
};
while (1) {
    $word .= substr ($l, int (rand (length ($l))), 1) for (1..4);
    my $tmp;
    print ( ( $tmp = get ("http://sprunge.us/${word}") ) eq "${word} not found" ? "[-] http://sprunge.us/${word} not found.\n" : "[+] http://sprunge.us/${word} found! Trying another..\n" );
    push @found, "http://sprunge.us/${word}" if $tmp ne "${word} not found";
    $word = "";
    sleep (1);
}
 
[ot] ciao robertof, potresti spiegarmi gentilmente l'utilizzo di $word .= , cioè che significa .= e quando lo si usa -.-"
so che è una domanda stupida, ma è l'unica cosa che non capisco del tuo sorcio....
grazie[/ot]
 
weed ha detto:
[ot] ciao robertof, potresti spiegarmi gentilmente l'utilizzo di $word .= , cioè che significa .= e quando lo si usa -.-"
so che è una domanda stupida, ma è l'unica cosa che non capisco del tuo sorcio....
grazie[/ot]

È append, $word .= " a" == $word = "${word} a"
 
Stato
Discussione chiusa ad ulteriori risposte.