PDA

View Full Version : [VB6] POST Multipart/Form-Data Question



d0w_
10-25-2009, 08:23 AM
I have been searching the internet for an way to post multipart headers but I cannot seem to find anything that helps me out... I am not doing a straight up upload, there are other variables that need to be posted as well.

for instance.

var1=email
var2=replyemail
var3=body
var4=Optional file upload

then post.

I'm familiar with posting regular variables, but not converting them to boundaries....

Just looking for maybe a quick example or a point in the right direction.

mcbain
10-25-2009, 08:38 AM
I have been searching the internet for an way to post multipart headers but I cannot seem to find anything that helps me out... I am not doing a straight up upload, there are other variables that need to be posted as well.

for instance.

var1=email
var2=replyemail
var3=body
var4=Optional file upload

then post.

I'm familiar with posting regular variables, but not converting them to boundaries....

Just looking for maybe a quick example or a point in the right direction.


just do exactly what your browser does. eof

d0w_
10-25-2009, 11:08 AM
Dim sFormData As String
Dim sFileBody As String
Dim ac As Integer
Dim strBody As String
Dim strFile As String



strBody = strBody & "Content-Disposition: form-data; name=""" & "pageState" & """" & vbCrLf & vbCrLf & "reply"
strBody = strBody & vbCrLf

strBody = strBody & "Content-Disposition: form-data; name=""" & "from" & """" & vbCrLf & vbCrLf & "email@email.com"
strBody = strBody & vbCrLf

strBody = strBody & "Content-Disposition: form-data; name=""" & "fromVerify" & """" & vbCrLf & vbCrLf & "email@email.com"
strBody = strBody & vbCrLf

strBody = strBody & "Content-Disposition: form-data; name=""" & varBody & """" & vbCrLf & vbCrLf & "MESSAGEBOXTEXT"
strBody = strBody & vbCrLf

strFile = "C:\pic.jpg"

strBody = strBody & "Content-Disposition: form-data; name=""" & "attachment" & """; filename=""" & "pic.jpg" & """" & vbCrLf & _
"Content-Type: image/jpeg" & vbCrLf & vbCrLf & strFile & vbCrLf



Inet.Execute "http://site.com/Reply.html?var1=blah", "POST", strBody, "Referer: http://site.com/Reply?var1=blah" & vbCrLf & "Content-Type: multidata/form-data"





I tried that, but that is not working either. Perhaps I'm doing something wrong.

graham23s
10-25-2009, 12:52 PM
code from my personal craigslist poster if help:



Dim boundary As String
Dim strTemp As String
strTemp = DateTime.Now.Ticks.ToString("x")
boundary = StrDup(40 - strTemp.Length, "-") & strTemp

'// PostingKey
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""postingKey""" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(postingKey & vbCrLf)

'// PostingTest
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""test""" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(postingTest & vbCrLf)

'// First hidden class data 1
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & explodeValues0(1).ToString & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(explodeValues0(2).ToString & vbCrLf)

'// Title
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & titValue & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(formMain.textBoxPostingTitle.Text & vbCrLf)

'// Age
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & ageValue & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(formMain.textBoxAge.Text & vbCrLf)

'// Location
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & locValue & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(formMain.textBoxLocation.Text & vbCrLf)

'// From email
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""FromEmail""" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(efrValue & vbCrLf)

'// Show email value
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & emlValue & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append("C" & vbCrLf)

'// First hidden class data 2
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & explodeValues1(1).ToString & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(explodeValues1(2).ToString & vbCrLf)

'// Body value
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & bodValue & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(formMain.textBoxPostBody.Text & vbCrLf)

'// Image 1
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""image1""" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append("add" & vbCrLf)

POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""imgfile1""; filename=""" & "C:\stacey-on-holiday.jpg" & """" & vbCrLf)
POSTData1.Append("Content-Type: image/jpeg" & vbCrLf)
POSTData1.Append(vbCrLf)

'// First hidden class data 3
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & explodeValues2(1).ToString & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append(explodeValues2(2).ToString & vbCrLf)

'// Continue button value
POSTData1.Append("--" & boundary & vbCrLf)
POSTData1.Append("Content-Disposition: form-data; name=""" & btnValue & """" & vbCrLf)
POSTData1.Append(vbCrLf)
POSTData1.Append("Continue" & vbCrLf)

'// Make a request for the desired web page
Dim POSTRequest1 As HttpWebRequest = CType(WebRequest.Create("https://post.craigslist.org/" & posKeyURL & posURLDigit & threeDigitCode & "none/x/" & (postingKey) & "/" & (postingTest)), HttpWebRequest)

'// Encode the POST data to bytes
Dim POSTBytes1 As Byte() = Encoding.ASCII.GetBytes(POSTData1.ToString)

'// Encode boudary bytes
Dim POSTBoundary1 As Byte() = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n")

'// Set other options
With POSTRequest1
.Method = "POST"
.KeepAlive = True
.AllowAutoRedirect = True
.CookieContainer = POSTCookieContainer0
.ContentType = "multipart/form-data; boundary=" & boundary
.ContentLength = POSTBytes1.Length

If formOptions.CheckBoxRandomizeUserAgent.Checked = True Then

'// Initialise the random user agent code
Dim randomUserAgent As New Random

.UserAgent = formOptions.ComboBoxUserAgent.Items.Item(randomUse rAgent.Next(0, formOptions.ComboBoxUserAgent.Items.Count))

Else

'// Else just use this one
.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"

End If

'// Has proxies been used?
If (formMain.checkBoxUseproxies.Checked = True And formProxies.listViewProxies.Items.Count > 0) Then

'// Use the proxy
.Proxy = proxyToUse

End If

.ProtocolVersion = HttpVersion.Version10
.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*"


End With

'Dim byteArray As Byte() = Encoding.GetBytes(POSTData1.ToString)

'// Set the datastream ready to send the POST request
Dim POSTStream1 = POSTRequest1.GetRequestStream()

'// Send the data
POSTStream1.Write(POSTBytes1, 0, POSTBytes1.Length)

'// Set up the response
Dim POSTResponse1 As HttpWebResponse = CType(POSTRequest1.GetResponse(), HttpWebResponse)

'// Add cookies to the cookie jar
POSTCookieContainer0.Add(POSTResponse1.Cookies)

'// Set up the streamreader
Dim POSTStreamReader1 As New StreamReader(POSTResponse1.GetResponseStream)

'// Debugging
Dim POSTHTML1 As String = POSTStreamReader1.ReadToEnd()

'// Close everything up
POSTStream1.Close()
POSTStreamReader1.Close()


Do you get any type of errors? what i do is have the html written to an .html file for debugging purposes then just loan it up and see exactly where the code stopped working.

if you want to tell me the webpage ill have a look at whats going wrong.

cheers

Graham

d0w_
10-25-2009, 02:08 PM
thanks ghram, but your code is in .net i beleive... i understand that concept, but im a little confused in areas.


here is the multimedia headers i received when i post




-----------------------------444916925658
Content-Disposition: form-data; name="oid"

oid:2510036
-----------------------------444916925658
Content-Disposition: form-data; name="pageState"

reply
-----------------------------444916925658
Content-Disposition: form-data; name="from"

kelley1@dormjunkies.com
-----------------------------444916925658
Content-Disposition: form-data; name="fromVerify"

kelley1@dormjunkies.com
-----------------------------444916925658
Content-Disposition: form-data; name="f78dc7699d2bce316662cbcf7f63cade"

hey i think your very cute
-----------------------------444916925658
Content-Disposition: form-data; name="attachment"; filename="kelley2.jpg"
Content-Type: image/jpeg








I'm not sure how i can bundle all of those ups and get the boundary in visual basic 6.

Zain
10-25-2009, 03:40 PM
not sure what you mean by get the boundary?

Audio
10-25-2009, 03:52 PM
-----------------------------444916925658
?
Just do a regex or something

d0w_
10-25-2009, 03:53 PM
not sure what you mean by get the boundary?



i get this from wireshark(packetsniff)

MIME Multipart Media Encapsulation, Type: multipart/form-data, Boundary: "---------------------------444916925658"

some kinda of boundary

Zain
10-25-2009, 03:55 PM
boundary is a string of the clients choice that you define as something that probably shouldnt occur anywhere in the data with a bunch of dashes before, so that the server can parse through the data. see graham's code where he just made it the datetime in ticks

you could even just define it as "444916925658" just like your browser

d0w_
10-25-2009, 04:21 PM
boundary is a string of the clients choice that you define as something that probably shouldnt occur anywhere in the data with a bunch of dashes before, so that the server can parse through the data. see graham's code where he just made it the datetime in ticks

you could even just define it as "444916925658" just like your browser


ok, that part solved, i am still stuck in a rut about actually coding the post.

this is the post execute im using







Dim sFormData As String
Dim sFileBody As String
Dim ac As Integer
Dim strBody As String
Dim strFile As String



strBody = strBody & "--444916925658" & vbCrLf & "Content-Disposition: form-data; name=""" & "pageState" & """" & vbCrLf & vbCrLf & "reply"
strBody = strBody & vbCrLf

strBody = strBody & "--444916925658" & vbCrLf & "Content-Disposition: form-data; name=""" & "from" & """" & vbCrLf & vbCrLf & "admin@dormjunkies.com"
strBody = strBody & vbCrLf

strBody = strBody & "--444916925658" & vbCrLf & "Content-Disposition: form-data; name=""" & "fromVerify" & """" & vbCrLf & vbCrLf & "admin@dormjunkies.com"
strBody = strBody & vbCrLf

strBody = strBody & "--444916925658" & vbCrLf & "Content-Disposition: form-data; name=""" & varBody & """" & vbCrLf & vbCrLf & "hey I think your really cute"
strBody = strBody & vbCrLf

strFile = "C:\kelley.jpg"

strBody = strBody & "--444916925658" & vbCrLf & "Content-Disposition: form-data; name=""" & "attachment" & """; filename=""" & "kelley.jpg" & """" & vbCrLf & _
"Content-Type: image/jpeg" & vbCrLf & vbCrLf & strFile & vbCrLf

MsgBox strBody

Inet.Execute "http://albany.backpage.com/MenSeekWomen/classifieds/Reply.html?oid=oid:1647646", "POST", strBody, "Referer: http://albany.backpage.com/MenSeekWomen/classifieds/Reply?oid=oid:1647646" & vbCrLf & "Content-Type: multipart/form-data; Boundary: ---------------------------444916925658"

pureSmack
10-25-2009, 04:56 PM
uhm ok. look at the boundary you are adding in the header field, and then look at the one you're using in the packet.

---------------------------444916925658
--444916925658

if you tell it to look for a boundary with this many dashes: ---------------------------

but only provide it -- dashes, it's not going to know where to parse.

as a side note, most of the time the bounday field in the header containt two less dashes than the body. also, i haven't seen the packet logs so i couldn't say for sure, but there is almost always one final boundary that follows your file data and ends with --

ie

---------------------------342524525425--

at the end of the packet.

d0w_
10-25-2009, 07:15 PM
uhm ok. look at the boundary you are adding in the header field, and then look at the one you're using in the packet.

---------------------------444916925658
--444916925658

if you tell it to look for a boundary with this many dashes: ---------------------------

but only provide it -- dashes, it's not going to know where to parse.

as a side note, most of the time the bounday field in the header containt two less dashes than the body. also, i haven't seen the packet logs so i couldn't say for sure, but there is almost always one final boundary that follows your file data and ends with --

ie

---------------------------342524525425--

at the end of the packet.



A+ help from everyone. My program works flawlessly now.

Thanks again.