lolamontes69

Python / Lola69's HTTP Requester

Jun 7th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.98 KB | None | 0 0
  1. import subprocess
  2. from tkFileDialog import askopenfilename
  3. from tkFileDialog import asksaveasfilename
  4. from Tkinter import *
  5. import Tkinter as tk
  6. import webbrowser
  7.  
  8. class Http_Requestings(object):
  9.     """ Coded by Lola69. 07 Jun 2013. """
  10.  
  11.     def add_headers(self):
  12.         textout = self.textframe.get(1.0, END)
  13.         lines = textout.split('\n')
  14.         c = ""
  15.         for a in lines:
  16.             if len(a) > 0:
  17.                 b = '-H "'+a+'" '
  18.                 c += b
  19.         return c
  20.  
  21.     def run_request(self,inputcommand):
  22.         print inputcommand
  23.         result = self.execute_unix(inputcommand)
  24.         self.textframe.delete(1.0, END)
  25.         self.textframe.insert(END, result)
  26.  
  27.     def add_default(self):
  28.         text1 = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; en) Opera 9.0"
  29.         self.textframe.delete(1.0, END)
  30.         self.textframe.insert(END, text1)
  31.        
  32.     def make_menu(self):
  33.         self.the_menu = tk.Menu(self.moot, tearoff=0)
  34.         self.the_menu.add_command(label="Cut")
  35.         self.the_menu.add_command(label="Copy")
  36.         self.the_menu.add_command(label="Paste")
  37.         self.the_menu.add_separator()
  38.         self.the_menu.add_command(label="Select all")
  39.  
  40.     def event_select_all(self, *args):
  41.         self.textframe.focus_force()        
  42.         self.textframe.tag_add("sel","1.0","end")
  43.  
  44.     def show_menu(self, e):
  45.         w = e.widget
  46.         self.the_menu.entryconfigure("Cut",command=lambda: w.event_generate("<<Cut>>"))
  47.         self.the_menu.entryconfigure("Copy",command=lambda: w.event_generate("<<Copy>>"))
  48.         self.the_menu.entryconfigure("Paste",command=lambda: w.event_generate("<<Paste>>"))
  49.         self.the_menu.entryconfigure("Select all", command=self.event_select_all)  
  50.  
  51.         self.the_menu.tk.call("tk_popup", self.the_menu, e.x_root, e.y_root)
  52.  
  53.     def execute_unix(self,inputcommand):
  54.         p = subprocess.Popen(inputcommand, stdout=subprocess.PIPE, shell=True)
  55.         (output, err) = p.communicate()
  56.         return output
  57.  
  58.     def open_in_browser(self):
  59.         url = self.entry.get()
  60.         new = 2
  61.         webbrowser.open(url,new=new)
  62.  
  63.     def delete_request(self):
  64.         try:
  65.             url = self.entry.get()
  66.             c = self.add_headers()
  67.             inputcommand = "curl -X DELETE "+c+url+' -v'
  68.             self.run_request(inputcommand)
  69.         except: pass
  70.  
  71.     def get_request(self):
  72.         try:
  73.             url = self.entry.get()
  74.             c = self.add_headers()
  75.             inputcommand = "curl "+c+url+' -v'
  76.             self.run_request(inputcommand)
  77.         except: pass
  78.  
  79.     def head_request(self):
  80.         try:
  81.             url = self.entry.get()
  82.             c = self.add_headers()
  83.             inputcommand = "curl -I "+c+url+' -v'
  84.             self.run_request(inputcommand)
  85.         except: pass
  86.  
  87.     def katy_request(self):
  88.         try:
  89.             url = self.entry.get()
  90.             c = self.add_headers()
  91.             inputcommand = "curl -X KATY "+c+url+' -v'
  92.             self.run_request(inputcommand)
  93.         except: pass
  94.  
  95.     def options_request(self):
  96.         try:
  97.             url = self.entry.get()
  98.             c = self.add_headers()
  99.             inputcommand = "curl -X OPTIONS "+c+url+' -v'
  100.             self.run_request(inputcommand)
  101.         except: pass
  102.  
  103.     def post_request_nodata(self):
  104.         try:
  105.             url = self.entry.get()
  106.             c = self.add_headers()
  107.             inputcommand = "curl -X POST "+c+url+' -v'
  108.             self.run_request(inputcommand)
  109.         except: pass
  110.  
  111.     def put_request_nodata(self):
  112.         try:
  113.             url = self.entry.get()
  114.             c = self.add_headers()
  115.             inputcommand = "curl -X PUT "+c+url+' -v'
  116.             self.run_request(inputcommand)
  117.         except: pass
  118.  
  119.     def put_request_upload(self):
  120.         try:
  121.             url = self.entry.get()
  122.             c = self.add_headers()
  123.             inputcommand = 'curl -T "README.txt" '+c+url+' -v'
  124.             self.run_request(inputcommand)
  125.         except: pass
  126.  
  127.     def trace_request(self):
  128.         try:
  129.             url = self.entry.get()
  130.             c = self.add_headers()
  131.             inputcommand = "curl -X TRACE "+c+url+' -v'
  132.             self.run_request(inputcommand)
  133.         except: pass
  134.  
  135.     def track_request(self):
  136.         try:
  137.             url = self.entry.get()
  138.             c = self.add_headers()
  139.             inputcommand = "curl -X TRACK "+c+url+' -v'
  140.             self.run_request(inputcommand)
  141.         except: pass
  142.  
  143.     def write_README(self):
  144.         readmestring = "Examples for Developers\nhttp://drupal.org/project/examples\n\n\nThis set of modules is intended to provide small working examples of Drupal's\nfeatures and APIs.  The modules strive to be simple, well documented and\nmodification friendly to help developers quickly learn their inner workings,\nwith a little reading and hands on experience.\n\nYou can have a quick glimpse at the current Examples in the demo site: \nhttp://d7.drupalexamples.info/\n\nSuggestions, corrections and new examples are welcome.  Don't be shy if you're\njust starting, as precisely because of that you will know the questions and\nproblems of a newcomer better than a seasoned developer!\n\nSetup\n\n1. Install Examples for Developers (unpacking it to your Drupal\n   sites/all/modules directory if you're installing by hand, for example).\n2. Enable any Example modules in Admin menu > Site building > Modules.\n3. Rebuild access permissions if you are prompted to.\n4. Profit!  The examples will appear in your Navigation menu (on the left\n   sidebar by default; you'll need to reenable it if you removed it).\n\nNow you can read the code and its comments and see the result, experiment with\nit, and hopefully quickly grasp how things work.\n\nIf you find a problem, incorrect comment, obsolete or unproper code or such,\nplease let us know by creating a new issue at\nhttp://drupal.org/project/issues/examples\n"
  145.         out = open('README.txt', 'w')
  146.         out.write(readmestring)
  147.         out.close        
  148.        
  149.     def clear_textbox(self):
  150.         clearscreen = ""
  151.         self.textframe.delete(1.0, END)
  152.         self.textframe.insert(END, clearscreen)
  153.  
  154.     def about_callback(self):
  155.         try:
  156.             text1 = ""
  157.             lainey = tk.Tk()
  158.             lainey.title('About this Program.')
  159.             text1 = "Coded by Lola69\n\nMake some HTTP requests\n????\nProfit"
  160.             lainey.config(background="black")
  161.             self.label1 = tk.Label(lainey, text=text1, background='white')
  162.             self.label1.pack(padx=5, pady=5)
  163.             lainey.mainloop()
  164.         except:
  165.             return
  166.  
  167.     def browse_callback(self):
  168.         try:
  169.             self.filename = askopenfilename(filetypes = [('All','*'),("Text",'*.txt')])
  170.             locallist = []
  171.             fin = open(self.filename)
  172.             for line in fin:
  173.                 locallist.append(line)
  174.             self.text4 = ''.join(locallist)
  175.             self.textframe.delete(1.0, END)
  176.             self.textframe.insert(END, self.text4)
  177.         except:
  178.             return
  179.  
  180.     def save_callback(self):
  181.         try:
  182.             saveas = asksaveasfilename(filetypes = [('All','*'),("Text",'*.txt')])
  183.             textout = self.textframe.get(1.0, END)
  184.             text_file = open(saveas, "w")
  185.             text_file.write(textout)
  186.             text_file.close()
  187.         except: pass
  188.  
  189.     def config(self):
  190.         self.moot = tk.Tk()
  191.         self.moot.config(background='black')
  192.         self.make_menu()
  193.         self.moot.title('LOLA69 HTTP REQUEST Program')
  194.         self.menubar = tk.Frame(self.moot, borderwidth=1, bg="black")
  195.         self.menubar.pack()
  196.  
  197.         self.mb_file = tk.Menubutton(self.menubar,text='File')
  198.         self.mb_file.config(background="black", fg="red")
  199.         self.mb_file.pack(side='left')
  200.         self.mb_file.menu = tk.Menu(self.mb_file)
  201.         self.mb_file.menu.add_command(label='open...', command=self.browse_callback)
  202.         self.mb_file.menu.add_command(label='save as...', command=self.save_callback)
  203.         self.mb_file.menu.add_command(label='close',command=self.moot.quit)
  204.  
  205.         self.mb_actions = tk.Menubutton(self.menubar,text='Tools')
  206.         self.mb_actions.config(background="black", fg="red")
  207.         self.mb_actions.pack(side='left')
  208.         self.mb_actions.menu = tk.Menu(self.mb_actions)
  209.         self.mb_actions.menu.add_command(label="Clear Textbox", command=self.clear_textbox)
  210.         self.mb_actions.menu.add_command(label="Add default User agent", command=self.add_default)
  211.         self.mb_actions.menu.add_command(label="Open URL in browser", command=self.open_in_browser)
  212.         self.mb_actions.menu.add_command(label="Make HEAD Request", command=self.head_request)
  213.         self.mb_actions.menu.add_command(label="Make POST Request without data", command=self.post_request_nodata)
  214.         self.mb_actions.menu.add_command(label="Make PUT Request without data", command=self.put_request_nodata)
  215.         self.mb_actions.menu.add_command(label="Make OPTIONS Request", command=self.options_request)
  216.         self.mb_actions.menu.add_command(label="Make DELETE Request", command=self.delete_request)
  217.         self.mb_actions.menu.add_command(label="Make TRACE Request", command=self.trace_request)
  218.         self.mb_actions.menu.add_command(label="Make TRACK Request", command=self.track_request)
  219.         self.mb_actions.menu.add_command(label="Make KATY Request", command=self.katy_request)
  220.         self.mb_actions.menu.add_command(label="Make PUT Request with file upload", command=self.put_request_upload)
  221.         self.mb_actions.menu.add_command(label="Create uploadfile README.txt", command=self.write_README)
  222.  
  223.         self.mb_help = tk.Menubutton(self.menubar,text='Help')
  224.         self.mb_help.config(background="black", fg="red")
  225.         self.mb_help.pack(padx=25, side='right')
  226.         self.mb_help.menu = tk.Menu(self.mb_help)
  227.         self.mb_help.menu.add_command(label='About', command=self.about_callback)
  228.  
  229.         self.entry = tk.Entry(self.moot, background='white')
  230.         self.entry.insert(END, "http://")
  231.         self.entry.pack(padx=1, pady=5)
  232.         self.entry.bind_class("Entry", "<Button-3><ButtonRelease-3>", self.show_menu)
  233.  
  234.         self.button = tk.Button(self.moot, text="Make GET request", background="black", fg="red", command=self.get_request)
  235.         self.button.pack(padx=5, pady=5)
  236.  
  237.         self.mb_file['menu'] = self.mb_file.menu
  238.         self.mb_actions['menu'] = self.mb_actions.menu
  239.         self.mb_help['menu'] = self.mb_help.menu
  240.  
  241.         self.scrollbar = tk.Scrollbar(self.moot, troughcolor='black')   #scrollbar
  242.         self.scrollbar.pack(side=RIGHT, fill=Y)    #scrollbar
  243.  
  244.         self.text1 = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; en) Opera 9.0"
  245.         self.textframe = tk.Text(self.moot, wrap=WORD, yscrollcommand=self.scrollbar.set,background='white', fg='black', font=('sans', 12))    #scrollbar
  246.         self.textframe.insert(END, self.text1)
  247.         self.textframe.pack(expand=1, fill='both', side=BOTTOM)
  248.         self.textframe.bind_class("Text", "<Button-3><ButtonRelease-3>", self.show_menu)
  249.         self.scrollbar.config(command=self.textframe.yview)    #scrollbar
  250.         self.moot.mainloop()
  251.  
  252. boxxy = Http_Requestings()
  253. boxxy.config()
  254.  
  255. """ ############################
  256.    #  Lola69's HTTP Requester #
  257.    #   A simple pentest-tool  #
  258.    ############################
  259.    
  260. Maybe I should have wrote some documentation on methods usage
  261. but I'm sure people know how to use a search engine.
  262.  
  263. Output is both on Terminal and in the GUI's textbox.
  264.  
  265. The headers are put into the textbox like the example
  266. on seperate lines using the same format ie- head: value
  267.  
  268. Add a default user agent so 'curl+system-disclosure' isnt used instead.
  269. The POST and PUT request are very basic, just to test if the
  270. methods are accepted.
  271.  
  272. Open can be used to load a list of headers, or you can even use this
  273. as a simple text editor(cut and paste are included).
  274. Save will save everything in the textbox. """
Advertisement
Add Comment
Please, Sign In to add comment