1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP] DeathByCaptcha - Yes, i need a help again...

Discussion in 'Visual Basic .NET' started by carlx, Mar 26, 2012.

  1. carlx

    carlx Registered Member

    Joined:
    Dec 28, 2008
    Messages:
    95
    Likes Received:
    88
    Hi Everybody,

    I have spent the past few hours playing with the DeathByCaptcha API to try and get it to work! ... As you guessed, with no luck!

    If anybody can help with a sample code of a working DBC code for vb.net that would be great.

    Im using framework 4.0
     
    Last edited: Mar 26, 2012
  2. carlx

    carlx Registered Member

    Joined:
    Dec 28, 2008
    Messages:
    95
    Likes Received:
    88
    I am using this to get the base64 value of the image before sending it to DBC//

    Code:
    Dim imageData() As Byte
            Dim fileStream As FileStream = File.OpenRead("C:\captchaimage.jpg")
            imageData = New Byte((fileStream.Length) - 1) {}
            fileStream.Read(imageData, 0, imageData.Length)
            fileStream.Close()
            Dim Image As String = System.Convert.ToBase64String(imageData)
    
    When i send it, i get a 413 response "request entity too large" ... the base64 string is huge, am i doing something wrong?
     
  3. Gr33nHat

    Gr33nHat Jr. VIP Jr. VIP

    Joined:
    Dec 21, 2009
    Messages:
    430
    Likes Received:
    150
    Occupation:
    Death By Captcha Co-Founder
    Location:
    Behind a Proxy near you
    Hi,

    Try to use:

    EncodeFile('C:\Users\Carl\Desktop\captchaaa.jpg',C:\Users\Carl\Desktop\captchaaa_base64.jpg)

    Then open C:\Users\Carl\Desktop\captchaaa_base64.jpg and send that file to our API.

    Let me know if anything,

    Bes Regards,
     
  4. carlx

    carlx Registered Member

    Joined:
    Dec 28, 2008
    Messages:
    95
    Likes Received:
    88
    I found this code, but im not entirely sure how to call it from my application, could somebody PM me or let me know what i need to do to send and receive the captcha.

    Code:
    Imports System
    Imports System.Threading
    
    Imports DeathByCaptcha
    Imports System.Text
    Imports System.IO
    Imports System.Net
    Imports System.Drawing.Imaging
    
    Public Class DBC
        Private username As String, password As String, captchaId As String
        Private _timeout As Integer = 10
        Private _maxTimeout As Integer = 50
    
        ''' <summary>
        ''' Time to wait, in seconds, before checking for an answer
        ''' </summary>
        Public Property timeout() As Integer
            Get
                Return _timeout
            End Get
            Set(ByVal value As Integer)
                _timeout = value
            End Set
        End Property
    
        ''' <summary>
        ''' Maximum time to wait in seconds
        ''' </summary>
        Public Property maxTimeout() As Integer
            Get
                Return _maxTimeout
            End Get
            Set(ByVal value As Integer)
                _maxTimeout = value
            End Set
        End Property
    
        Public Sub New(ByVal _username As String, ByVal _password As String)
            username = "username"
            password = "pass"
        End Sub
    
        ''' <summary>
        ''' Send a captcha to DBC and wait for an answer
        ''' </summary>
        Public Function sendCaptcha(ByVal captcha As Image) As String
            Dim captchaAnswer As String = String.Empty
    
            Dim str2 As String = ""
            Dim str As String = "exploitnDBC"
            Dim builder As New StringBuilder()
            Using stream As New MemoryStream()
                captcha.Save(stream, ImageFormat.Jpeg)
                Dim src As Byte() = stream.ToArray()
                builder.Append("--" & str & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""username""")
                builder.Append(vbCr & vbLf & "Content-Length: " & username.Length & vbCr & vbLf & vbCr & vbLf)
                builder.Append(username)
                builder.Append(vbCr & vbLf)
                builder.Append("--" & str & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""password""")
                builder.Append(vbCr & vbLf & "Content-Length: " & password.Length & vbCr & vbLf & vbCr & vbLf)
                builder.Append(password)
                builder.Append(vbCr & vbLf)
                builder.Append("--" & str & vbCr & vbLf & "Content-Disposition: form-data; name=")
                builder.Append("""captchafile""; filename=""captcha""")
                builder.Append(vbCr & vbLf)
                builder.Append("Content-Type: application/octet-stream")
                builder.Append(vbCr & vbLf & "Content-Length: " & src.Length & vbCr & vbLf & vbCr & vbLf)
                Dim bytes As Byte() = Encoding.ASCII.GetBytes(builder.ToString())
                Dim buffer__1 As Byte() = Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & str & "--" & vbCr & vbLf)
                Dim dst As Byte() = New Byte(((bytes.Length + src.Length) + (buffer__1.Length - 1))) {}
                Buffer.BlockCopy(bytes, 0, dst, 0, bytes.Length)
                Buffer.BlockCopy(src, 0, dst, bytes.Length, src.Length)
                Buffer.BlockCopy(buffer__1, 0, dst, bytes.Length + src.Length, buffer__1.Length)
                Try
                    Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://api.deathbycaptcha.com/api/captcha"), HttpWebRequest)
                    request.Method = "POST"
                    request.ContentType = "multipart/form-data; boundary=" & str
                    request.ContentLength = dst.Length
                    request.ServicePoint.Expect100Continue = False
                    Using stream2 As Stream = request.GetRequestStream()
                        stream2.Write(dst, 0, dst.Length)
                    End Using
                    Using response As WebResponse = request.GetResponse()
                        Using stream3 As Stream = response.GetResponseStream()
                            Using reader As New StreamReader(stream3)
                                str2 = reader.ReadToEnd()
                            End Using
                        End Using
                    End Using
                    Dim resp As New System.Collections.Hashtable()
                    For Each s As String In str2.Split("&"c)
                        resp.Add(s.Split("="c)(0), s.Split("="c)(1))
                    Next
                    If resp.Contains("captcha") Then
                        captchaId = DirectCast(resp("captcha"), String)
                        If Integer.Parse(captchaId) > 0 Then
                            captchaAnswer = String.Empty
                            Dim timeoutCount As Integer = 0
                            Do
                                If timeoutCount >= _maxTimeout Then
                                    removeCaptcha()
                                    Return String.Empty
                                End If
                                resp = New System.Collections.Hashtable()
                                System.Threading.Thread.Sleep(_timeout * 1000)
                                Dim wc As New WebClient()
                                Dim result As String = wc.DownloadString("http://api.deathbycaptcha.com/api/captcha/" & captchaId)
                                resp = New System.Collections.Hashtable()
                                For Each s As String In result.Split("&"c)
                                    resp.Add(s.Split("="c)(0), s.Split("="c)(1))
                                Next
                                If resp.Contains("text") Then
                                    If DirectCast(resp("text"), String) <> String.Empty Then
                                        captchaAnswer = DirectCast(resp("text"), String)
                                    End If
                                End If
                                timeoutCount += _timeout
                            Loop While captchaAnswer = String.Empty
                        End If
                    End If
                Catch
                    captchaAnswer = String.Empty
                    If captchaId <> String.Empty Then
                        removeCaptcha()
                    End If
                End Try
                Return captchaAnswer
            End Using
        End Function
    
        ''' <summary>
        ''' Report a bad captcha to DBC
        ''' </summary>
        Public Sub reportBadCaptcha()
            If captchaId <> String.Empty Then
                Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://api.deathbycaptcha.com/api/captcha/" & captchaId & "/report"), HttpWebRequest)
                req.Method = "POST"
                req.ContentType = "application/x-www-form-urlencoded"
                Using writeStream As Stream = req.GetRequestStream()
                    Dim encoding__1 As New UTF8Encoding()
                    Dim bytes As Byte() = encoding__1.GetBytes("username=" & username & "&password=" & password)
                    writeStream.Write(bytes, 0, bytes.Length)
                End Using
                Dim result As String = String.Empty
                Using response As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
                    Using responseStream As Stream = response.GetResponseStream()
                        Using readStream As New StreamReader(responseStream, Encoding.UTF8)
                            result = readStream.ReadToEnd()
                        End Using
                    End Using
                End Using
            End If
        End Sub
    
        Private Sub removeCaptcha()
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://api.deathbycaptcha.com/api/captcha/" & captchaId & "/remove"), HttpWebRequest)
            req.Method = "POST"
            req.ContentType = "application/x-www-form-urlencoded"
            Using writeStream As Stream = req.GetRequestStream()
                Dim encoding__1 As New UTF8Encoding()
                Dim bytes As Byte() = encoding__1.GetBytes("username=" & username & "&password=" & password)
                writeStream.Write(bytes, 0, bytes.Length)
            End Using
            Dim result As String = String.Empty
            Using response As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
                Using responseStream As Stream = response.GetResponseStream()
                    Using readStream As New StreamReader(responseStream, Encoding.UTF8)
                        result = readStream.ReadToEnd()
                    End Using
                End Using
            End Using
        End Sub
    
        ''' <summary>
        ''' Get the account balance
        ''' </summary>
        Public Function getBalance() As String
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://api.deathbycaptcha.com/api/user"), HttpWebRequest)
            req.Method = "POST"
            req.ContentType = "application/x-www-form-urlencoded"
            Using writeStream As Stream = req.GetRequestStream()
                Dim encoding__1 As New UTF8Encoding()
                Dim bytes As Byte() = encoding__1.GetBytes("username=" & username & "&password=" & password)
                writeStream.Write(bytes, 0, bytes.Length)
            End Using
            Dim result As String = String.Empty
            Using response As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
                Using responseStream As Stream = response.GetResponseStream()
                    Using readStream As New StreamReader(responseStream, Encoding.UTF8)
                        result = readStream.ReadToEnd()
                    End Using
                End Using
            End Using
            result = result.Remove(0, result.IndexOf("balance=") + 8)
            result = result.Remove(result.IndexOf("&"), result.Length - result.IndexOf("&"))
            Dim parseBal As Double = Double.Parse(result)
            parseBal /= 100.0
            Return parseBal.ToString()
        End Function
    End Class
    Cheers.
     
    Last edited: Mar 28, 2012
  5. theMagicNumber

    theMagicNumber Regular Member

    Joined:
    May 13, 2010
    Messages:
    345
    Likes Received:
    195
    Does it compile? If so:
    Code:
    Dim YourCaptcha As Image //Set the captcha
    Dim DBCClient As DBC = New DBC("yourusername", "yourpassword")
    Dim CaptchaResponse As String = DBCClient.sendCaptcha(YourCaptchaAsImage)
    
    To convert image from byte array you can use the following code
    Code:
     Dim YourCaptcha As System.Drawing.Image
     Dim ImageData As Byte() = System.IO.File.ReadAllBytes("pic.jpg")
     Using ImageStream As New System.IO.MemoryStream(ImageData)
          YourCaptcha = System.Drawing.Image.FromStream(ImageStream)
     End Using
    
     
    Last edited: Mar 28, 2012
  6. w84it

    w84it Regular Member

    Joined:
    Jun 18, 2009
    Messages:
    442
    Likes Received:
    752
    Here's my function i use:
    Code:
     Function GetCaptchaDBC(ByVal imagepath As String) As String
            Dim captchaclient As DeathByCaptcha.SocketClient = New DeathByCaptcha.SocketClient(decuser, decpass)
            Try
                Writelog("DeathByCaptcha Logged In - Balance: $" + captchaclient.Balance.ToString)
                Dim fs As New FileStream(imagepath, FileMode.Open, FileAccess.Read)
                Dim br As New BinaryReader(fs)
                Dim image As Byte() = br.ReadBytes(CInt(fs.Length))
                br.Close()
                fs.Close()
                Dim retst As DeathByCaptcha.Captcha = captchaclient.Decode(image)
                Dim retstring As String = ""
                If retst.Solved Then
                    retstring = retst.Text
                End If
                If retstring = "" Then
                    captchaclient = Nothing
                    Return "null"
                Else
                    captchaclient = Nothing
                    Return retstring
                End If
            Catch ex As Exception
                Writelog(ex.Message)
                captchaclient = Nothing
                Return "null"
            End Try
        End Function
    
     
  7. carlx

    carlx Registered Member

    Joined:
    Dec 28, 2008
    Messages:
    95
    Likes Received:
    88
    When i compile the program it gives me the following error.

    Code:
    Type 'DeathByCaptcha.Captcha' is not defined
    
    I don't understand why...

     
  8. carlx

    carlx Registered Member

    Joined:
    Dec 28, 2008
    Messages:
    95
    Likes Received:
    88
    I've just read an old post regarding this, i think its to do with the framework being used, i have switched to 3.0 and it compiled.