Tools Python CGI + Source | JaAViEr::0x5d

Iniciado por JaAViEr, Abril 23, 2013, 10:13:29 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Abril 23, 2013, 10:13:29 PM Ultima modificación: Mayo 03, 2014, 11:20:32 AM por Flemon
Hola, buen día damas y caballeros :P.

En esta ocasión vengo a mostrar el código de fuente de unas aplicaciones que pasé a Python CGI , para poder ejecutarlas en el servidor y no depender de una maquina con Python instalado...


Sus respectivos códigos de fuente...
De/Codificador Base64:
Código: python

#!/usr/bin/python
#Autor: 0x5d::JaAViEr
#Twitter: @0x5d
import cgi, os, base64

def form_inicial():
form_html = '''
<form action="" method="POST">
<textarea name="content"></textarea><br />
<select name="option">
<option value="encode">Codificar</option>
<option value="decode">Decodificar</option>
</select><br />
<input type="Submit" value="Enviar"><br />
Creado bajo Python CGI.<br />
Autor : JaAViEr (0x5d)
</form>'''
return base("De/Codificar Base64", form_html)

def base(title, content):
code = '''
<div class="ui-widget-content">
<div class="ui-widget-header">%s</div>
%s
</div>
'''%(title, content)
return code

print "content-type:text/html\r\n\r\n"

print '''
<title>De/Codificador Base64</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/cupertino/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<style>
div {
text-align:center;
font-size:0.5cm;
}
input, select {
height:0.7cm;
font-size:0.4cm;
}
</style>
'''

form = cgi.FieldStorage()
opcion = form.getvalue("option")
texto = form.getvalue("content")
method = os.environ['REQUEST_METHOD']
if method == "POST":
if opcion:
if opcion == "encode":
print form_inicial()
print base("Salida", "<textarea>"+cgi.escape(base64.b64encode(texto))+"</textarea>")
elif opcion == "decode":
print form_inicial()
print base("Salida", "<textarea>"+cgi.escape(base64.b64decode(texto))+"</textarea>")
else:
print form_inicial()
print base("Error", "Opción incorrecta")
else:
print form_inicial()
print base("Error", "Por favor selecciona una opción")
else:
print form_inicial()


Cifrar Rot13 / Atbash:
Código: python

#!/usr/bin/python
#Autor: 11Sep
#To CGI: 0x5d::JaAViEr
#Twitter: @0x5d
import cgi, os

def  formulario_inicial():
form_html = '''
<form action="" method="POST">
Data: <br/>
<textarea name="contenido"></textarea><br />
<select name="opcion">
<option value="rot13">ROT13</option>
<option value="atbash">Atbash</option>
</select><br />
<input type="Submit"><br/>
Programado por <b>11Sep</b><br />
Programado en CGI por <b>JaAViEr::0x5d</b>
</form>
'''
return base("Cifrar Rot13/Atbash", form_html)

def base(title, content):
code = '''
<div class="ui-widget-content">
<div class="ui-widget-header">%s</div>
%s
</div>
'''%(title, content)
return code

def rot13(palabra):
    Cifrado = ''
    for i in palabra:
        buff = ord(i)
        if (buff >= 65 and buff <= 90) or (buff >= 97 and buff <= 122):
            if ((buff + 13 > 90 and buff + 13 <= 103) or (buff + 13 > 122 and buff + 13 <= 135)):
                Cifrado += chr(buff -13)
            else:
                Cifrado += chr(buff + 13)
    return Cifrado
   
def atbash(palabra):
    V1 = "abcdefghijklm"
    V2 = "zyxwvutsrqpon"
   
    Buff = ""
   
    for i in range(len(palabra)):
        for a in range(len(V1)):
            if V1[a] == palabra[i]:
                Buff += V2[a]
            elif V2[a] == palabra[i]:
                Buff += V1[a]
    return Buff

print "content-type:text/html\r\n\r\n"
print '''
<title>Cifrar Rot13/Atbash 11Sep::JaAViEr</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/blitzer/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<style>
div {
text-align:center;
font-size:0.5cm;
}
input, select {
height:0.7cm;
font-size:0.4cm;
}
</style>
'''
form = cgi.FieldStorage()
method = os.environ['REQUEST_METHOD']
contenido = form.getvalue("contenido")
opcion = form.getvalue("opcion")
if method == "POST":
if opcion:
if opcion == "rot13":
print formulario_inicial()
print base("Salida", "<textarea>"+rot13(contenido)+"</textarea>")
elif opcion == "atbash":
print formulario_inicial()
print base("Salida", "<textarea>"+atbash(contenido)+"</textarea>")
else:
print formulario_inicial()
print base("ERROR","Opción inválida")
else:
print formulario_inicial()

Enviar peticiones POST:
Código: python

#!/usr/bin/python
#Autor: 0x5d::JaAViEr
#Twitter: @0x5d
import cgi, os, urllib, sys

def base(title, content):
code = '''
<div class="ui-widget-content">
<div class="ui-widget-header">%s</div>
%s
</div>
'''%(title, content)
return code

print "content-type:text/html\r\n\r\n"
print '''
<title>Enviar datos POST online :: JaAViEr(0x5d)</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/cupertino/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<style>
div {
text-align:center;
font-size:0.5cm;
}
input, select {
height:0.7cm;
font-size:0.4cm;
}
</style>
'''
form = cgi.FieldStorage()
method = os.environ['REQUEST_METHOD']
campos = form.getvalue("campos")
valores = form.getvalue("valores")
url = form.getvalue("url")
if method == "POST":
dic = {}
if not "http://" in url:
  print base("ERROR!","No se puede conectar a %s<br/><a href='send_post.py'>Volver</a>"%cgi.escape(url))
  sys.exit(1)
if len(campos)>0 and len(valores)>0:
for d,i in zip(campos.split(),valores.split(":-:")):
dic['%s'%d] = i
try:
print urllib.urlopen(url, urllib.urlencode(dic)).read()
except:
print "No se puede conectar a", cgi.escape(url)
else:
form_html = '''
<form action="" method="POST">
URL: <input type="Text" name="url" value="http://"><br />
Campos (separados por un espacio): <input type="Text" name="campos"><br />
Campos (separados por ":-:"): <input type="Text" name="valores"><br />
<input type="Submit"><br/>
Funcionando bajo Python CGI<br />
Author: <u>JaAViEr::0x5d</u>
</form>
'''
print base("ENVIAR DATOS POR POST", form_html)
form_example = '''
URL: <input type="Text" name="url" value="http://web.com/login.php" disabled><br />
Campos (separados por un espacio): <input type="Text" name="campos" value="user password" disabled><br />
Campos (separados por ":-:"): <input type="Text" name="valores" value="0x5d:-:miclave123" disabled><br />
<input type="Submit" onclick=alert("TEST");><br/>
'''
print base("Ejemplo de uso", form_example)


Fuente: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
   
Saludos , Javier.
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Muy bueno brother, le tengo que hechar un vistazo al módulo CGI.

Saludos!







You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Buena hermano.
Sigueme en Twitter : @Sankosk
Estos nuevos staff no tienen puta idea XD

Abril 24, 2013, 10:32:57 AM #3 Ultima modificación: Abril 24, 2013, 10:35:32 AM por JaAViEr
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Muy bueno brother, le tengo que hechar un vistazo al módulo CGI.

Saludos!
Es muy interesante, tienes las mismas opciones que PHP , pero con la belleza de Python :D
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Buena hermano.
Muchas Gracias !
Saludos.
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

buena bro yo tambien hice algo asi en perl.

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
buena bro yo tambien hice algo asi en perl.
Wow con CGI ? Genial, he visto perl CGI, pero como no soy amigo de Perl ni una entendí :(
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login