Author Topic: Bruteforce'ish counting algorithm  (Read 3970 times)

0 Members and 1 Guest are viewing this topic.

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Bruteforce'ish counting algorithm
« on: April 08, 2011, 10:51:26 pm »
Hi


So, I am sitting and doing some coding and then suddenly I am in need of a bruteforce like algorithm to create a list of arguments like this:
a=&b=&c=

Like a URL's arguments. This list is to be generated from an array of names of the arguments {a,b,c}. And all of this is easy enough, but there are a rule. No arguments are to be listed twice in the list and the amount of arguments can vary from 1 to infinite.

Example with the argument names a,b and c:

a=&
b=&
c=&
a=&b=
a=&c=
c=&b=
a=&b=&c=

That would be all possible valid combinations of the arguments a, b and c if I am not mistaken. However, how would you programaticly create a algorithm that can generate such a list from any array input of the type above? I just cant twist my head around it, maybe its just me being dumb atm, maybe not. Help are appreciated.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline I_Learning_I

  • Knight
  • **
  • Posts: 267
  • Cookies: 26
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: Bruteforce'ish counting algorithm
« Reply #1 on: April 08, 2011, 11:21:30 pm »
Just like in the URL Bruteforce topic, you'll need for's to specify the number of characters.
1 For = 1 Char
2 For's = 2 Chars

But then just do something like:

$myget="GET ".$mycharset[$i]."=&\r\n";

The problem is that you don't want to start off with:
a=&a=&a=&a=&a=&a=&a=&a=&a=&

But with
a=&

Which means you'll either have a lot of if's OR a function for a number of characters, liek the following:
Code: [Select]
function charnum1(){

    for( $i=0; $i<sizeof($mycharset);$i++){
                $myget="GET ".$mycharset[$i]."=&\r\n";
                 //Send and Receive         
    }
}

And then another for 2 chars
Code: [Select]
function charnum2(){

   for($f=0;$f<sizeof($mycharset);$f++){
        for( $i=0; $i<sizeof($mycharset);$i++){
                $myget="GET ".$mycharset[$i]."=&".$mycharset[$f]."=&\r\n";
                //Send and Recieve
          }
   }
}


And then a main code that would do something like:

Code: [Select]
charnum1();
charnum2();
charnum3();

Post any more doubts
Thanks for reading,
I_Learning_I

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #2 on: April 08, 2011, 11:24:26 pm »
a=&
b=&
c=&
a=&b=
a=&c=
c=&b=
a=&b=&c=


Do you want to Continue it like:
a=&b=&c=&d=
or
a=&b=&c=&d=&
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #3 on: April 08, 2011, 11:26:42 pm »
Just like in the URL Bruteforce topic, you'll need for's to specify the number of characters.
1 For = 1 Char
2 For's = 2 Chars

But then just do something like:

$myget="GET ".$mycharset[$i]."=&\r\n";

The problem is that you don't want to start off with:
a=&a=&a=&a=&a=&a=&a=&a=&a=&

But with
a=&

Which means you'll either have a lot of if's OR a function for a number of characters, liek the following:
Code: [Select]
function charnum1(){

    for( $i=0; $i<sizeof($mycharset);$i++){
                $myget="GET ".$mycharset[$i]."=&\r\n";
                 //Send and Receive         
    }
}

And then another for 2 chars
Code: [Select]
function charnum2(){

   for($f=0;$f<sizeof($mycharset);$f++){
        for( $i=0; $i<sizeof($mycharset);$i++){
                $myget="GET ".$mycharset[$i]."=&".$mycharset[$f]."=&\r\n";
                //Send and Recieve
          }
   }
}


And then a main code that would do something like:

Code: [Select]
charnum1();
charnum2();
charnum3();

Post any more doubts


Yes, I am aware that I can do that. But I was hoping there was a possibility of making a loop algorithm that would limit the amount of lines to less than 500... :P Thanks for reply anyway :)



Do you want to Continue it like:
a=&b=&c=&d=
or
a=&b=&c=&d=&


Only for as long as the amount of arguments. That is, if there are 3 arguments (a,b,c) it should stop at a=&b=&c=
« Last Edit: April 08, 2011, 11:27:17 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #4 on: April 08, 2011, 11:40:47 pm »
Code: (vb) [Select]
Function Something(ByVal ListOfStuff As List(Of String)) As List(Of String)
        Dim ResList As New List(Of String)
        For A As Integer = 0 To ListOfStuff.Count - 1
            Dim Templist As New List(Of String)
            Templist.Add(ListOfStuff(A))
            For B As Integer = 1 To ListOfStuff.Count - 1
                For C As Integer = 1 To B
                    'Checking
                    Dim Isin = False
                    For D As Integer = 0 To Templist.Count - 1
                        If Templist(D) = ListOfStuff(C) Then Isin = True
                    Next
                    If Not Isin Then Templist.Add(ListOfStuff(C))
                Next
            Next
            ResList.Add(Join(Templist.ToArray, "=&"))
        Next
        Return ResList
    End Function
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline I_Learning_I

  • Knight
  • **
  • Posts: 267
  • Cookies: 26
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: Bruteforce'ish counting algorithm
« Reply #5 on: April 08, 2011, 11:42:19 pm »
Well you could do the following:

Code: [Select]

$mycharset = array("","a","b","c","d","etc....");

for($count1=0;$count1<sizeof($mycharset);$count1++){
        for($count2=0;$count2<sizeof($mycharset);$count2++){
                 for($count3=1;$count3<sizeof($mycharset);$count3++){
                            if($count2==0){
                                   $myget="GET ".$mycharset[$count3]."=&\r\n";
                            }elseif($count1==0){
                                 $myget="GET ".$mycharset[$count3]."=&".$mycharset[$count2]."=&\r\n";
                            }else{
                                $myget="GET ".$mycharset[$count3]."=&".$mycharset[$count2]."=&".$mycharset[$count1]."=&\r\n";
                            }
                  }
        }
}

This should work and be less than 500 lines.
Will have less than 50 lines :P
« Last Edit: April 09, 2011, 12:10:15 am by I_Learning_I »
Thanks for reading,
I_Learning_I

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #6 on: April 08, 2011, 11:46:00 pm »
Code: (vb) [Select]
Function Something(ByVal ListOfStuff As List(Of String)) As List(Of String)
        Dim ResList As New List(Of String)
        For A As Integer = 0 To ListOfStuff.Count - 1
            Dim Templist As New List(Of String)
            Templist.Add(ListOfStuff(A))
            For B As Integer = 1 To ListOfStuff.Count - 1
                For C As Integer = 1 To B
                    'Checking
                    Dim Isin = False
                    For D As Integer = 0 To Templist.Count - 1
                        If Templist(D) = ListOfStuff(C) Then Isin = True
                    Next
                    If Not Isin Then Templist.Add(ListOfStuff(C))
                Next
            Next
            ResList.Add(Join(Templist.ToArray, "=&"))
        Next
        Return ResList
    End Function

Its actually not that far from, but not working quite as planned. When you enter a and b in the list it will give:

a=b=
b=

Its suppose to output
a=
b=
a=b=

don't mind the = and & formating, thats an easy fix.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #7 on: April 08, 2011, 11:57:41 pm »
Code: [Select]
Function Something(ByVal ListOfStuff As List(Of String)) As List(Of String)
        Dim ResList As New List(Of String)
        For A As Integer = 0 To ListOfStuff.Count - 1
            For B As Integer = 0 To ListOfStuff.Count - 1
                Dim Templist As New List(Of String)
                Templist.Add(ListOfStuff(A))
                For C As Integer = 0 To B
                    'Checking
                    Dim Isin = False
                    For D As Integer = 0 To Templist.Count - 1
                        If Templist(D) = ListOfStuff(C) Then Isin = True
                    Next
                    If Not Isin Then Templist.Add(ListOfStuff(C))
                Next
                ResList.Add(Join(Templist.ToArray, "=&"))
            Next
        Next
        Return ResList
    End Function
this gave me:
a
a=&b
a=&b=&c
b=&a
b=&a
b=&a=&c
c=&a
c=&a=&b
c=&a=&b
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #8 on: April 09, 2011, 12:05:35 am »
Still not quite there. For a,b,c it should be something like this:
a=
b=
c=
a=b=
a=c=
b=c=
a=b=c=
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #9 on: April 09, 2011, 12:46:18 am »
Still not quite there. For a,b,c it should be something like this:
a=
b=
c=
a=b=
a=c=
b=c=
a=b=c=
isn't that simply:
Code: [Select]
For I as integer = 0 to ListOfStuff.count - 1
reslist.add(listofStuff(I))
next
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #10 on: April 09, 2011, 12:59:05 am »
isn't that simply:
Code: [Select]
For I as integer = 0 to ListOfStuff.count - 1
reslist.add(listofStuff(I))
next

No, that would just spit out a b c
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #11 on: April 09, 2011, 01:07:11 am »
No, that would just spit out a b c
yeah But I mean add it in front of the other Code I gave you
so:

Code: (vb) [Select]
Function Something(ByVal ListOfStuff As List(Of String)) As List(Of String)
        Dim ResList As New List(Of String)
        For I as integer = 0 to ListOfStuff.Count - 1
            Reslist.add(ListOfStuff(I))
        Next
        For A As Integer = 0 To ListOfStuff.Count - 1
            For B As Integer = 0 To ListOfStuff.Count - 1
                Dim Templist As New List(Of String)
                Templist.Add(ListOfStuff(A))
                For C As Integer = 0 To B
                    'Checking
                    Dim Isin as boolean = False
                    For D As Integer = 0 To Templist.Count - 1
                        If Templist(D) = ListOfStuff(C) Then Isin = True
                    Next
                    If Not Isin Then Templist.Add(ListOfStuff(C))
                Next
                    Isin = False
                    For D As Integer = 0 To ResList.Count - 1
                        If ResList(D) = Join(Templist.ToArray, "=&") Then Isin = True
                    Next
                    If Not Isin Then ResList.Add(Join(Templist.ToArray, "=&"))
            Next
        Next
        Return ResList
    End Function
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: Bruteforce'ish counting algorithm
« Reply #12 on: April 09, 2011, 01:18:03 am »
This is not what I wanted to do, becouse you have to edit it if you need yo work with longer arrays. It could be do with a recursive function, but I am too tired to be able to code it:

Code: [Select]
#include <stdlib.h>
int main()
{
    char *pos[]={"a", "b", "c" };
    int c=3;
    int i=0;
    int a=0;
    int b=0;
    int max=0;
    // c=3; n=3
    for(i=0; i<c; i++)
    {
        // x=0
        printf("%s\n", pos[i]); // No bucle
        b=i;
               
        // x=1
        for(a=i+1; a<c; a++) // x=1 so 1 bucle
        {
            printf("%s%s\n", pos[i], pos[a]);  // This would be done like int alpha=c-(i+1); for(t=0; t<alpha; t++) printf("%s", pos[i+alpha]
        }
        // x=2
        for(a=i+1; a<c; a++)  // x=2 so 1 bucle
        {
            for(b=a+1; b<c; b++)  // and 2 bucles
                printf("%s%s%s\n", pos[i], pos[a], pos[b]);
        }
    }
    getc(stdin);
}

How this should be done:
Having a n elements array.
 
We need n "for" bucles, indexed by x from 0 to n.
Each one of these would have from x=0 to x=n-1 bucles inside. If x=0, no bucle, just printf.
Each one of these sub bucles would have a for inside being its limit x having a printf inside. This is to print character by character.

I don't hope you understand me becouse actually I don't understand myself at this hours very well, but I have tried...

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #13 on: April 09, 2011, 02:12:23 am »
Okay lol, I did it! After.. 5+ hours of fooling around :P Ill clean up the code and post a function here in a few mins :)

EDIT: Here goes:

The Class:
Code: [Select]
Class GETParameterGenerator
    ''' <summary>
    ''' Nice brute-force function translated from C#
    ''' </summary>
    Public CharSet As String()
    Public Power As Integer
    Public Function Count() As IEnumerable(Of String)
        Dim max As Long = CLng(Math.Pow(CDbl(CharSet.Length), CDbl(Power)))
        Dim counts As Long() = New Long(Power - 1) {}
        Dim retstr As New List(Of String)
        For i As Long = 0 To max - 1
            retstr.Add(IncrementArray(counts, i))
        Next
        Return retstr
    End Function
    Public Function IncrementArray(ByRef counts As Long(), ByVal count As Long) As String
        Dim temp As Long = count
        For i As Integer = Power - 1 To 0 Step -1
            Dim pow As Long = CLng(Math.Pow(CharSet.Length, i))
            counts(i) = temp \ pow
            temp = temp Mod pow
        Next

        Dim sb As New System.Text.StringBuilder()
        For Each c As Integer In counts
            sb.Insert(0, CharSet(c) + "|")
        Next
        Return sb.ToString()
    End Function

    ''' <summary>
    ''' My function
    ''' </summary>
    Function GenerateAllPossebilities(ByVal Arguments() As String)
        CharSet = Arguments

        ' This will generate a array of ALL possebilities with the Argument list a, aa, ab, ac, ad etc etc. Brute-force style
        Dim Arr1 As New ArrayList
        For i As Integer = 0 To CharSet.Length
            Power = i
            For Each cc As String In Count()
                If cc <> "" Then
                    Arr1.Add(cc)
                End If
            Next
        Next

        ' First filter. This will remove diplicate arguments inside each of the rows(a|a|b, a|b|b etc)
        Dim arr2 As New ArrayList
        For i As Integer = 0 To Arr1.Count - 1
            Dim argstmp() As String = Arr1(i).ToString.Split("|")
            Dim args As New ArrayList
            For x As Integer = 0 To argstmp.Length - 1
                If argstmp(x) <> "" Then
                    args.Add(argstmp(x))
                End If
            Next

            Dim passed As Boolean = True
            For c As Integer = 0 To args.Count - 1
                Dim restoftheargs As New ArrayList(args)
                restoftheargs.RemoveAt(c)

                If restoftheargs.Contains(args(c)) Then
                    passed = False
                End If
            Next
            If passed Then
                Dim addstr As String = ""
                For y As Integer = 0 To args.Count - 1
                    addstr += args(y) & "|"
                Next
                addstr = addstr.Substring(0, addstr.Length - 1)
                arr2.Add(addstr)
            End If
        Next

        ' Second filter. This will remove duplicates in all the rows (a|b <-> b|a etc)
        Dim arr3 As New ArrayList
        For i As Integer = 0 To arr2.Count - 1
            Dim tmpstr01() As String = arr2(i).ToString.Split("|")
            Array.Sort(tmpstr01)
            Dim fin As String = ""
            For m As Integer = 0 To tmpstr01.Length - 1
                fin += tmpstr01(m) & "|"
            Next

            Dim located As Boolean = False
            For i2 As Integer = 0 To arr2.Count - 1
                If Not i = i2 Then
                    Dim tmpstr02() As String = arr2(i2).ToString.Split("|")
                    Array.Sort(tmpstr02)
                    Dim fin2 As String = ""
                    For m As Integer = 0 To tmpstr02.Length - 1
                        fin2 += tmpstr02(m) & "|"
                    Next
                    If fin = fin2 Then
                        arr2(i2) = "-1"
                    End If
                End If
            Next

            arr3.Add(arr2(i))
        Next

        Dim done As New ArrayList
        For i As Integer = 0 To arr3.Count - 1
            If arr3(i) <> "-1" Then
                done.Add(arr3(i))
            End If
        Next

        Return done
    End Function

End Class


Usage:
Code: [Select]
Dim MyGetParameterGenerator As New GETParameterGenerator
Dim TheArguments() As String = {"a", "b", "c"}
Dim FinalResult As ArrayList = MyGetParameterGenerator.GenerateAllPossebilities(TheArguments)

Will spit out:
Quote
a
b
c
a|b
a|c
b|c
a|b|c


I am 100% sure there is a better way of doing this, but it works so, meh :P
« Last Edit: April 09, 2011, 02:27:14 am by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: Bruteforce'ish counting algorithm
« Reply #14 on: April 09, 2011, 04:56:51 am »
@ande, good work dude you did it +1