This forum is in archive mode. You will not be able to post new content.

Author Topic: [Python]Xware  (Read 1055 times)

0 Members and 1 Guest are viewing this topic.

Offline DeXtreme

  • Peasant
  • *
  • Posts: 95
  • Cookies: 8
  • I was there and you never knew.
    • View Profile
    • My Designs
[Python]Xware
« on: July 20, 2013, 01:23:27 AM »
I wrote this script to help me with the Pentesterlab iso so i thought i'd share ;D
It has three functions:a url encoder(for multiple vars),an ascii to unicode convertor and function to split any text(by whitespace or by character) and join them with specified character or text.
For those of you also exploring the Pentesterlab iso,this script helps in the XSS and the SQL injection examples.

Pentesterlab site:https://pentesterlab.com/web_for_pentester.html

Code: (python) [Select]
import urllib

#dictionary of commands
cmdic={'u':'unic()','url':'urlenc()','dnc':'dnc()'}

#Functions
def unic():
    """ASCII to UNICODE endcoder(u)"""
    string = raw_input("Code:")
    #Split string into list of characters
    string = list(string)
    uni=""
    #Convert each character to unicode
    for char in string:uni = uni + str(ord(char)) + ","
    uni = uni.strip(",")
    print uni + "\n"
   
def urlenc():
    """URL encoder(url)"""
    try:
        num = raw_input("Number of vars:")
        x = 0
        varlist = []
        while x < int(num):
            var = raw_input("Variable:")
            val = raw_input("Value:")
            #Form list of tuples of vars and values
            varlist.append((var,val.decode('string-escape')))
            x+=1
        #Make dictionary of vars and values
        varlist = dict(varlist)
        print urllib.urlencode(varlist) + "\n"
    except Exception as err:
        print "Error:%s\n" %err

def dnc():
    """Divide And Conquer(dnc)-Splits and joins code with given text"""
    string = raw_input("Divide:")
    sjoin = raw_input("Conquer:")
    print "Enter 'w' for whitespace or 'c' for character"
    stype = raw_input("By:").lower()
    if stype == 'w':
        string = string.split()
        string = sjoin.join(string)
        print string + "\n"
    elif stype == 'c':
        string = list(string)
        string = sjoin.join(string)
        print string + "\n"



print "DeX Xware\n"
print "Enter 'l' for a list of available commands\nEnter 'q' to quit\n"


while True:
    cmd = raw_input("Command:")
    if cmd in cmdic:
        exec(cmdic[cmd])
    elif cmd.lower() == "q":
        break
    elif cmd.lower() == "l":
        for doc in cmdic.values():
            exec("print %s.__doc__" %(doc.replace("()","")))
    else:
        print "Command not found\n"
« Last Edit: July 20, 2013, 03:58:53 PM by DeXtreme »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [Python]Xware
« Reply #1 on: July 20, 2013, 07:34:13 AM »
Great code actually, I don't see anything to pick on, except that you could space out the words and symbols, like:
Code: (python) [Select]
for char in string:uni=uni+str(ord(char))+","
print uni+"\n"
x+=1

Would make the code more readable.

Also you might want to add more explanation about what it does.
« Last Edit: July 20, 2013, 07:34:35 AM by Kulverstukas »

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python]Xware
« Reply #2 on: July 20, 2013, 10:03:33 AM »
I modified your post to add syntax highlighting.
>>>import this
-----------------------------

Offline DeXtreme

  • Peasant
  • *
  • Posts: 95
  • Cookies: 8
  • I was there and you never knew.
    • View Profile
    • My Designs
Re: [Python]Xware
« Reply #3 on: July 20, 2013, 03:23:49 PM »
Great code actually, I don't see anything to pick on, except that you could space out the words and symbols, like:
Code: (python) [Select]
for char in string:uni=uni+str(ord(char))+","
print uni+"\n"
x+=1

Would make the code more readable.

Also you might want to add more explanation about what it does.

Thanks Kulver,i sure will.

I modified your post to add syntax highlighting.

Gracias amigo

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [Python]Xware
« Reply #4 on: July 20, 2013, 03:32:43 PM »
Thanks Kulver,i sure will.
My post might have been confusing, but I meant to say, add spaces between words and symbols.

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.