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

C#, Login to Wordpress

Discussion in 'Black Hat SEO Tools' started by tehmadcracker, May 6, 2009.

  1. tehmadcracker

    tehmadcracker BANNED BANNED

    Joined:
    Apr 19, 2009
    Messages:
    155
    Likes Received:
    502
    I am having a hell of a time trying to get my c# code to login to the wordpress admin dashboard, has anyone on here dealt with this before? I sniffed the packets from FF->Dashboard, and from my app to the dashboard, I have all my cookies etc, but I must be missing something, any ideas are greatly appreciated
     
  2. crashed

    crashed Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 13, 2008
    Messages:
    958
    Likes Received:
    1,198
    Occupation:
    Guru-slayer
    Location:
    Behind the VPN...
    Home Page:
    What code are you using?

    Are you using the correct header? I.e. GET

    Wordpress implements several redirects during login.
     
  3. tehmadcracker

    tehmadcracker BANNED BANNED

    Joined:
    Apr 19, 2009
    Messages:
    155
    Likes Received:
    502
    public class WPWorkerTests
    {
    public CookieContainer cookieJar = new CookieContainer();

    public WPWorkerTests()
    {

    }

    public void StartAdmin(object obj)
    {
    CookieContainer cJar = new CookieContainer();
    string primer = getRequest("url to wordprss login", 0);
    string respAdmin = postRequest(wpaObject.url, "log=admin&pwd=adminpw&wp-submit=Log+In&testcookie=1&redirect_to=http%3A%2F%2Fwordpress domain%2Fwp-admin%2F", 0);
    string ha = getRequest("url to wordpress admin", 0);

    }

    public string getRequest(string url, int tries)
    {
    try
    {

    HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
    HttpWRequest.CookieContainer = cookieJar;
    HttpWRequest.UserAgent = "IE 9 Experimental";
    HttpWRequest.KeepAlive = true; //this is the default

    HttpWRequest.Timeout = 10000;
    HttpWRequest.Method = "GET";
    HttpWRequest.ServicePoint.ConnectionLimit = 100;

    HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
    StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), Encoding.ASCII);
    string response = sr.ReadToEnd().ToLower();
    sr.Close();

    return response.ToLower();
    }
    catch (Exception ex)
    {
    Console.WriteLine("Exception: " + url);

    if (ex.ToString().Contains("404") == true)
    {
    return "404";
    }
    else if (ex.ToString().Contains("500") == true)
    {
    return "";
    }

    if (tries > 1)
    {
    Console.WriteLine();
    Console.WriteLine(url);
    Console.WriteLine();
    Console.WriteLine(ex.ToString());
    }
    else
    {
    tries++;
    System.Threading.Thread.Sleep(500);
    return getRequest(url, tries);
    }
    }
    return "";
    }

    public string postRequest(string url, string postdata, int tries)
    {
    try
    {
    HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
    HttpWRequest.CookieContainer = cookieJar;
    HttpWRequest.UserAgent = "IE 9 Experimental";
    HttpWRequest.KeepAlive = true; //this is the default
    HttpWRequest.Referer = url;

    HttpWRequest.Timeout = 120000;
    HttpWRequest.Method = "POST";
    HttpWRequest.Referer = url;
    // add the content type so we can handle form data
    HttpWRequest.ContentType = "application/x-www-form-urlencoded";
    // we need to store the data into a byte array
    byte[] PostData = System.Text.Encoding.ASCII.GetBytes(postdata);
    HttpWRequest.ContentLength = PostData.Length;
    Stream tempStream = HttpWRequest.GetRequestStream();
    // write the data to be posted to the Request Stream
    tempStream.Write(PostData, 0, PostData.Length);
    tempStream.Close();

    HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
    StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), Encoding.ASCII);
    string response = sr.ReadToEnd().ToLower();
    sr.Close();

    return response.ToLower();


    }
    catch (Exception ex)
    {
    if (tries > 1)
    {
    Console.WriteLine(ex.ToString());
    }
    else
    {
    tries++;
    System.Threading.Thread.Sleep(500);
    return postRequest(url, postdata, tries);
    }
    }
    return "";
    }

    }
     
  4. cooooookies

    cooooookies Senior Member

    Joined:
    Oct 6, 2008
    Messages:
    1,008
    Likes Received:
    216
    What I did: I extended the xmlrpc interface of wordpress and wrote in java an xmlrpc submitter. Works very well. I initially also wanted to work with the admin interface, but this is very tedious and above all when an update of wordpress happens, you have to adjust many things. So my advice: have a look at /xmlrpc.php, check which funtions are already available (many!) and extend for what you need.
     
  5. tehmadcracker

    tehmadcracker BANNED BANNED

    Joined:
    Apr 19, 2009
    Messages:
    155
    Likes Received:
    502
    cool, thanks!