-
Notifications
You must be signed in to change notification settings - Fork 2
/
Req2Code.cs
133 lines (111 loc) · 3.86 KB
/
Req2Code.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Text;
using System.Windows.Forms;
using Fiddler;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
[assembly: Fiddler.RequiredVersion("2.2.4.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyTitle("Req2Code")]
[assembly: AssemblyDescription("Automatically generate python code of the selected request")]
[assembly: AssemblyCompany("www.infosec-wiki.com")]
[assembly: AssemblyProduct("Req2Code")]
namespace Req2Code
{
public class Req2Code : IFiddlerExtension
{
private TabPage oPage;
// private TextBox newTxt;
private RichTextBox newTxt;
private void TextBox_KeyPress(object sender, KeyPressEventArgs e){
TextBox textBox = sender as TextBox;
if (textBox == null)
return;
if (e.KeyChar == (char)1)
{
textBox.SelectAll();
e.Handled = true;
}
}
private void MyTextBox_DragEnter(object sender, DragEventArgs e){
e.Effect = DragDropEffects.Copy;
// MessageBox.Show("MyTextBox_DragEnter");
}
private void MyTextBox_DragDrop(object sender, DragEventArgs e){
DataObject v_obj = (DataObject)e.Data;
String output = "";
String[] v_formats = v_obj.GetFormats(false);
foreach (string v_format in v_formats){
// MessageBox.Show( v_format );
// output += v_format + "\r\n";
}
Session[] session_arr = (Session[]) v_obj.GetData("Fiddler.Session[]");
Session session = session_arr[0];
var req = session.oRequest;
var headers = req.headers;
String host = session.host;
String url = session.url;
String fullUrl = session.fullUrl;
bool isHTTPS = session.isHTTPS;
String RequestBody = System.Text.Encoding.Default.GetString( session.RequestBody );
String RequestMethod = session.RequestMethod;
String requestBodyBytes = System.Text.Encoding.Default.GetString( session.requestBodyBytes );
output = "#encoding=utf8\r\n";
output += "import requests\r\n";
output += "import warnings\r\n";
output += "warnings.filterwarnings(\"ignore\")\r\n\r\n";
output += "http_session = requests.Session()\r\n\r\n";
String func = "def my_request():\r\n";
func += "\turl = \"" + fullUrl + "\"\r\n";
func += "\theaders = {\r\n";
var header_arr = headers.ToArray();
foreach (HTTPHeaderItem header in header_arr){
String Name = header.Name;
String Value = header.Value;
// MessageBox.Show(Name+"="+Value);
func += "\t\t\"" + Name + "\": \""+ Value + "\",\r\n";
}
func += "\t}\r\n";
func += "\t\r\n";
if(RequestMethod == "POST"){
func += "\tpost_data = \"" + RequestBody + "\"\r\n";
func += "\tdata = http_session.post(url, data=post_data, headers=headers, verify=False).content\r\n";
}
else if(RequestMethod == "GET"){
func += "\tdata = http_session.get(url, headers=headers, verify=False).content\r\n";
}
func += "\treturn data\r\n\r\n";
output += func;
// MessageBox.Show(host);
// MessageBox.Show(url); // without http://
// MessageBox.Show(fullUrl);
// MessageBox.Show(RequestBody);
// MessageBox.Show(RequestMethod);
// MessageBox.Show(requestBodyBytes);
// MessageBox.Show("MyTextBox_DragDrop");
// newTxt.ReadOnly = false;
newTxt.Text = output;
}
public void OnLoad() {
oPage = new TabPage("Req2Code");
// newTxt = new TextBox();
newTxt = new RichTextBox();
// newTxt.Width = 400;
// newTxt.Height = 400;
newTxt.Multiline = true;
newTxt.AcceptsTab = true;
newTxt.AutoSize = true;
newTxt.ReadOnly = true;
newTxt.Dock = DockStyle.Fill;
newTxt.AllowDrop = true;
newTxt.DragDrop += new DragEventHandler(MyTextBox_DragDrop);
newTxt.DragEnter += new DragEventHandler(MyTextBox_DragEnter);
newTxt.KeyPress += TextBox_KeyPress;
oPage.Controls.Add(newTxt);
FiddlerApplication.UI.tabsViews.TabPages.Add(oPage);
}
public void OnBeforeUnload(){}
}
}