Jump to content
Flubber

[Py] peteava.ro anime embed code extractor

Recommended Posts

[!] Atentie! Acest program odata executat va face multe request-uri catre site-ul tinta. Nu rulati de pe calculatorul propriu pentru a nu fi catalogat drept `hacker de carton` ce vrea sa faca DoS.

Later edit:

Well, dupa o zi de coding, am ajuns la concluzia ca l-am scris de cacat (se blocheaza in anumite loop-uri, uneori nu extrage corect datele s.a.m.d.), asa ca singurul motiv pentru care il las ar fi analizarea lui.

#!/usr/bin/env python
# -- - - - - - - - --
# Coded in Python 2.7
# Acest script verifica paginile disponibile de pe www.peteava.ro categoria `Anime`
# Determina care este ultima pagina, iar apoi itereaza prin fiecare pagina luand
# codul sursa pentru embed, generand intr-un final o pagina html cu toate
# embed-urile.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

print "
[*] Procesez configurarile ... te rog asteapta.\n"
try:
import urllib2
except:
print "[-] Lipseste modulul \"urllib2\".\n"
print ImportError
exit(0)
try:
import os
except:
print "[-] Lipseste modulul \"os\".\n"
print ImportError
exit(0)
try:
from optparse import OptionParser
except:
print "[-] Functia \"OptionParser\" din modulul \"optparser\" nu a fost gasita.\n"
print ImportError
exit(0)
try:
from time import strftime
except:
print "[-] Functia \"strftime\" din modulul \"time\" nu a fost gasita.\n"
print ImportError
exit(0)

# Configuram parser-ul de argumente
args = OptionParser()
# -- -- -- -- -- -- -- -- -- -- -- --
args.add_option("-u", "--user-agent", help="User-agent:\n\t(default: 1)\n\t1. Mozilla Firefox 6.0;\n\t2. Internet Explorer 9.0;\n\t3. Opera 11.11;\n\t4. Chrome 15.0.872.0.", dest = "useragent", type="int")
args.add_option("-f", "--file", help="Fisierul HTML in care vor fi salvate codurile embed (default: log_<data curenta a sistemului ZZ.LL.AAAA_O.M.S>.html", dest = "obiect", type="string")
args.add_option("-v", "--verbose", help="Verbose? (default: 0); 1 - setat / 0 - nu este setat", dest = "verbose", type="int")
# -- -- -- -- -- -- -- -- -- -- -- --
(opts, args) = args.parse_args()
# - - - - - - - - - - - - - - - - - -
useragent = opts.useragent
verbose = opts.verbose
fobject = opts.obiect
# -- -- -- -- -- -- -- -- -- -- - - -

timestamp = "_" + str(strftime("%d.%m.%Y_%H.%M.%S")) + ".html"

if opts.verbose is None:
print "
[*] Nu s-a specificat o valoare anume pentru verbosity. Folosesc default: 0 (nu este setat).\n"
opts.verbose = 0

if opts.obiect is None:
print "
[*] Nu s-a specificat o valoare pentru optiunea \"-f/--file\". Folosesc default: log_<data curenta a sistemului ZZ.LL.AAAA_O.M.S>.html.\n"
opts.obiect = str('log'+str(timestamp))

if opts.useragent is None:
print "
[*] Nu s-a specificat user-agent-ul. Am sa folosesc user-agent prestabilit: Mozilla Firefox 6.0\n"
useragent = "Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0"
elif opts.useragent == 1:
print "[+] Am setat user-agent: Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0\n"
useragent = "Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0"
elif opts.useragent == 2:
print "[+] Am setat user-agent: Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)\n"
useragent = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"
elif opts.useragent == 3:
print "[+] Am setat user-agent: Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/5.0 Opera 11.11"
useragent = "Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/5.0 Opera 11.11"
elif opts.useragent == 4:
print "[+] Am setat user-agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2"
useragent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2"
# - END - - - - - - - - - - - - - - - -


prim = []
doi = []
trei = []
ids = []
idsf = []
ultimp = ""

def pagina():
# Inainte de a stoca id-urile disponibile, stabilim care este ultima pagina ce o putem accesa
req = urllib2.Request("http://www.peteava.ro/browse/categoria/102/pagina/1")
# Configuram `browser-ul` nostru
req.add_header('User-agent', useragent)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
print "[+] Configurarile au fost procesate cu succes.\n"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
upag = urllib2.urlopen(req)
upag = upag.read()

intgeta = upag.split()
intgetb = intgeta.index("if(page_bottom")+2
intAnte = intgeta[intgetb:intgetb+1]

for a in intAnte:
x = a.split(")")
x.pop(1)
for y in x:
ultimp = y
print "[+] Am detectat ultima pagina ca fiind: " + '"' + str(ultimp) + '"' + ".\n"
# - END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


# Luam toate `id-urile` de pe pagina si le stocam intr-o lista
def extractie():
pagina()

iterare = 1
print "[+] Incep `extractia` ... \n[!] Apasa Control-C (^C) pentru a intrerupe procesul.\n"
while iterare <= ultimp:
try:
urlsortare = "http://www.peteava.ro/browse/categoria/102/pagina/" + str(iterare)
req = urllib2.Request(urlsortare)
req = urllib2.urlopen(req)
stocare = req.read()
exa = stocare.split()
for a in exa:
if "href=\"/id-" in a:
b = a[6:]
prim.append(
else:
pass
for a in prim:
a = a.replace('"', "")
doi.append(a)
trei = set(doi)
for a in trei:
if verbose == 1:
print "
[*] Am adaugat id: " + str(a)
ids.append(a)
else:
ids.append(a)
iterare += 1
except KeyboardInterrupt as ki:
print "\n[Control-C] Keyboard interrupt. Inchei procesul.",ki
break
exit(0)
# - END - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Deschidem pagina HTML in care vom salva codurile embed
def procesare():
try:
extractie()
except (IOError, SystemExit) as eroare:
print "[-] Ceva a intervenit."
raise eroare
exit(0)

fisier = str(fobject) + str(timestamp)
print "[+] Creez log-ul html: \"" + str(fisier) + "\".\n"
fobj = open(fisier, "a")
fobj.write('<html>\n<title>Generat la data de ' + str(strftime("[%A] %d.%m.%Y %H:%M:%S")) + '</title>\n<body>\n<script type="text/javascript" language="javascript">\n\n')

urlembed = "http://www.peteava.ro"
pattern = "value=\"<object"
count = 1
eachdata = ""
fstring = ""
finalstring = ""
idsf = set(ids)

try:
for eid in idsf:
req = urllib2.Request(urlembed+str(eid))
req = urllib2.urlopen(req)
stocare = req.read()
exa = stocare.split()
for a in exa:
if pattern in a:
patternid = exa.index(pattern)
data = exa[patternid+1:patternid+24]
for dataa in data:
fstring = fstring + ' ' + dataa
finalstring = fstring.replace("<", "<").replace(">", ">").replace(""", '"').replace("&", "&")
if verbose == 1:
print "[+] Am scris urmatoarele: \"<object" + str(finalstring[:-4]) + "\" in fisierul: \"" + str(fisier) + "\"\n"
fobj.write("var video_embed_code" + str(count) + " = <object" + str(finalstring[:-4])+"\n")
count += 1
else:
fobj.write("var video_embed_code" + str(count) + " = <object" + str(finalstring[:-4])+"\n")
count += 1
else:
pass
fstring = ""
finalstring = ""

except (KeyboardInterrupt, IOError, SystemExit) as eroare:
print "[-] Ceva a intervenit."
raise eroare
exit(0)

fobj.write("\n</script>\n</body>\n</html>")
fobj.close()
print "[+] Am terminat.\n"
# - END - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


if __name__ == '__main__':
print "[+] Am pornit la data de: " + str(strftime("[%A] %d.%m.%Y %H:%M:%S")) + ".\n"
procesare()

sau Python code - 205 lines - codepad

Testat pana la pagina a 3-a, nu sunt dupes.

Testati-l si voi si reveniti cu feedback.

Programat datorita faptului ca l-am luat sub forma de challenge.

Pe viitor, loc de imbunatit:

- clase

- multithreading

- exceptii si mai friendly

- mai multe argumente (timeout la conexiuni s.a.m.d.)

- ??

Astept critici constructive, s.a.m.d.

Link to comment
Share on other sites

problema e ca il am testa pe un root si imi arata urmatoare problema ;) :

cum trebuie folosit :-?? ca am incercat mai multe forme dar nu stiu sa il folosesc

Nu iti mai bate capul, il las ca si PoC fiindca nu `functioneaza` cum trebuie.

Daca tot vrei sa iti faci nervi (vazandu-l cand se blocheaza in vreun loop sau nu extrage corect datorita variatiilor din codul sursa, dar si a codului prost scris):

python <numescript>.py -h

exemplu:

 python peteava.py -u 3 -f log1 -v 1

Link to comment
Share on other sites

Nu iti mai bate capul, il las ca si PoC fiindca nu `functioneaza` cum trebuie.

Daca tot vrei sa iti faci nervi (vazandu-l cand se blocheaza in vreun loop sau nu extrage corect datorita variatiilor din codul sursa, dar si a codului prost scris):

python <numescript>.py -h

exemplu:

 python peteava.py -u 3 -f log1 -v 1

incercat si la fel aceias problema :


[root@localhack ~]# python peteava.py -u 3 -f log1 -v 1
python: can't open file 'peteava.py': [Errno 2] No such file or directory
[root@localhack ~]# python teava.py -u 3 -f log1 -v 1
File "teava.py", line 139
except KeyboardInterrupt as ki:
^
SyntaxError: invalid syntax
[root@localhack ~]# python teava.py -h
File "teava.py", line 139
except KeyboardInterrupt as ki:
^
SyntaxError: invalid syntax
[root@localhack ~]#

Link to comment
Share on other sites

nu le am cu piton dar am facut unul in php daca aveti nevoie.

face pentru prima pagina, daca vreti toate paginile dati un for si inlocuiti pagina 1 cu i.

la fel si la categorie, l-am facut pt anime. e comentat. spor la embed

<?php
$paginaTrasa = file_get_contents('http://www.peteava.ro/browse/categoria/102/pagina/1');//trage pagina 1 in stringul $paginaTrasa
preg_match_all("/(thumbnail\/)(.*?)(\n)/", $paginaTrasa, $arrayCuAidiuri);//pastreaza doar id-ul si titlul fiecarui video si le baga in arrayul $arrayCuAidiuri
foreach($arrayCuAidiuri[2] as $aidi)//pentru fiecare array cu id-uri listeaza titlu si cod de embed
{
$aidiSiTitlu = explode('%%%', str_replace(array('/large" border="0" alt="','"'), array('%%%',''), $aidi));//scoatem caracterele naspa care au ramas intre id si titlu, bagam %%% intre ele apoi le punem intr-un array dupa ce le spargem cu %%% bagat mai devreme
print 'Titlu video:'.$aidiSiTitlu[1].'<br>';//titlu si mai jos codul ala de embed
print '<textarea rows="2" cols="100">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="394" id="swf_player_id_for_ie_who_sucks"><param name="movie" value="http://www.peteava.ro/static/swf/player.swf?3"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="menu" value="false"><param name="flashvars" value="streamer=http://content.peteava.ro/stream.php&file='.$aidiSiTitlu[0].'_standard.mp4?=http://storage2.peteava.ro/serve/thumbnail/'.$aidiSiTitlu[0].'/playerstandard&hd_file='.$aidiSiTitlu[0].'_high.mp4&hd_image=http://storage2.peteava.ro/serve/thumbnail/'.$aidiSiTitlu[0].'/playerhigh&autostart=false"><embed src="http://www.peteava.ro/static/swf/player.swf?3" id="__ptv_pl_'.$aidiSiTitlu[0].'_624_384__" name="__ptv_pl_'.$aidiSiTitlu[0].'_624_384__" width="640" height="394" allowscriptaccess="always" menu="false" allowfullscreen="true" flashvars="streamer=http://content.peteava.ro/stream.php&file='.$aidiSiTitlu[0].'_standard.mp4?=http://storage2.peteava.ro/serve/thumbnail/'.$aidiSiTitlu[0].'/playerstandard&hd_file='.$aidiSiTitlu[0].'_high.mp4&hd_image=http://storage2.peteava.ro/serve/thumbnail/'.$aidiSiTitlu[0].'/playerhigh&autostart=false"/></object><div style="background:#161616;width:640px;"><a href="http://www.filmeonlinesi70depopupuri.ro" style="font: bold 12px Arial; margin: 0px 0px 0px 5px; display:block; width:160px;color:#fff">Vezi mai multe pe site-ul tau ce plm ca te inbogatesti din popupuri de filme onlaine salam</a> </div>
</textarea><hr>';
}
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...