Skip to content

Instantly share code, notes, and snippets.

@dimzon

dimzon/sample.cs Secret

Created August 3, 2014 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimzon/d0d1100d179f455d33a4 to your computer and use it in GitHub Desktop.
Save dimzon/d0d1100d179f455d33a4 to your computer and use it in GitHub Desktop.
sample.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApplication1
{
class CSACaptureBreaker
{
private static readonly Regex CoralClean=new Regex(@"[^\d]",RegexOptions.Compiled);
public String BreakCoral(String captchaBase64)
{
var r = (HttpWebRequest) WebRequest.Create("http://127.0.0.1:8099/");//"gsa_test.gsa");
r.ServicePoint.Expect100Continue = false;
r.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
r.ContentType = @"multipart/form-data; boundary=----WebKitFormBoundarynu7U7xBmkURa26xU";
using (var ms = new MemoryStream())
{
using (var wr = new StreamWriter(ms, Encoding.ASCII))
{
wr.Write("------WebKitFormBoundarynu7U7xBmkURa26xU\r\n");
wr.Write("Content-Disposition: form-data; name=\"file\"; filename=\""+Guid.NewGuid().ToString("N")+".png\"\r\n");
wr.Write("Content-Type: image/png\r\n\r\n");
wr.Flush();
var img = Convert.FromBase64String(captchaBase64);
ms.Write(img,0,img.Length);
wr.Write("\r\n------WebKitFormBoundarynu7U7xBmkURa26xU--\r\n");
}
var q = ms.ToArray();
r.ContentLength = q.Length;
r.Method = @"POST";
//r.
using(var reqS=r.GetRequestStream())
{
reqS.Write(q,0,q.Length);
}
}
using(var rsp=r.GetResponse())
{
using(var rspS=rsp.GetResponseStream())
{
var a = new byte[rsp.ContentLength];
rspS.Read(a, 0, a.Length);
var str = Encoding.ASCII.GetString(a).Split(new char[]{'|'},6)[5];
Console.WriteLine(str);
return (CoralClean.Replace(str,"") + "12345").Substring(0,5);
}
}
}
}
class Program
{
static void Main(string[] args)
{
var cb = new CSACaptureBreaker();
var base64 = Convert.ToBase64String(File.ReadAllBytes(@"C:\1\a\coral-1017.png"));
for (var i = 0; i < 100; ++i)
{
Thread.Sleep(TimeSpan.FromSeconds(1));
if ("12345".Equals(cb.BreakCoral(base64))) return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment