Government Security
Network Security Resources

Jump to content

Photo

Permutation Generator

- - - - - tools distributed
  • Please log in to reply
7 replies to this topic

#1 gunknown

gunknown

    Private First Class

  • Members
  • 32 posts

Posted 15 January 2006 - 04:39 AM

Hi,

in search of new challenge I coded this tool to improve my coding skills. It creates all permutations (i.e. all possible different combinations) of the passed characters and writes them into a file.

-char array permutation generator v0.1-
							   -by gunknown-

												  [gunknown@oleco.net]

 usage:
 permutator.exe <characters to use> <maximum length of each permutation> [-e]

 ______
 permutator.exe will generate a file containing all permutations
 of the passed characters. By default it generates all permutations
 with every length up to the passed one.
 Use -e to generate all permutations with only the maximum length.

 Maximum characters allowed are 94.
 Maximum length of permutation is 100.

 Be aware of special characters like < > ` ! or " (os dependent).
 Put them between "" and pass them by escape-sequenzes respectively
 if necessary.

example: permutator.exe abcd 4 -e
output:
aaaa
aaab
aaac
aaad
aaba
...

Download the source and the exe file here.

Look at the code below:
[code=auto:0]/*
-char array permutation generator v0.1-
-by gunknown-
[gunknown@oleco.net]


usage: permutator.exe <characters to use> <maximum length of each permutation> [-e]

January '06

# ################################################################################
####
#
# Copyright (C) 2006 gunknown
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

*/

#include <iostream.h>
#include <fstream.h>

char* nextpermu(char*);
void header(void);
void usage(void);
int size, length;

int main(int argc, char* argv[])
{

header();
if(argc < 3){
usage();
return 0;}

size = strlen(argv[1]);
int finished = length = atoi(argv[2]);

//maximal 94 characters and 100 digits
if(size > 94 || finished > 100){
usage();
return 0;}


// "int possibilities" are possibilities for current amount of digits.
// "int total_possibilities" are possibilities for all amounts of digits together
double percent, possibilities=1.0, temp_possibilities = 1.0, total_possibilities = 0.0;
int total_counter = 0;
char* chars = argv[1];
char* permu;
char out[100];
ofstream output("output.txt", ios::out | ios::app);

// if -e option is not set
if(argc != 4)
{
length = 1;

// calculate total_possibilities
for(int j=1; j <= finished; ++j)
{
for(int i=1; i <= j; ++i)
temp_possibilities *= size;

total_possibilities += temp_possibilities;
temp_possibilities = 1.0;
}
}

// if -e option is set: total_possibilities = possibilities
else if(argc == 4){
for(int i=1; i <= length; ++i)
possibilities *= size;
total_possibilities = possibilities;}


cout << " possible combinations: " << total_possibilities << endl << endl;

// runs main programm loop for different amounts of digits
do{

// re-initialize variables for next amount of digits
int counter=0, i=0, j=0;
#ifdef WIN32
char* buff = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
#else
char* buff;
#endif
bool first = true;
possibilities=1.0;

// initialize buff
for(int i=0; i < length; ++i)
buff[i] = '!';
buff[length] = '\0';

// possibilities for current amount of digits
for(int i=1; i <= length; ++i)
possibilities *= size;


while(counter < possibilities)
{
if(!first)
buff = nextpermu(buff);
permu = buff;
first = false;

// translates char array like 0001 to permutation like aaab
while(i<length)
{

switch (permu[i])
{

case '!': out[j] = chars[0];
++j;
break;

case '"': out[j] = chars[1];
++j;
break;

case '#': out[j] = chars[2];
++j;
break;

case '$': out[j] = chars[3];
++j;
break;

case '%': out[j] = chars[4];
++j;
break;

case '&': out[j] = chars[5];
++j;
break;

case '\'': out[j] = chars[6];
++j;
break;

case '(': out[j] = chars[7];
++j;
break;

case ')': out[j] = chars[8];
++j;
break;

case '*': out[j] = chars[9];
++j;
break;

case '+': out[j] = chars[10];
++j;
break;

case ',': out[j] = chars[11];
++j;
break;

case '-': out[j] = chars[12];
++j;
break;

case '.': out[j] = chars[13];
++j;
break;

case '/': out[j] = chars[14];
++j;
break;

case '0': out[j] = chars[15];
++j;
break;

case '1': out[j] = chars[16];
++j;
break;

case '2': out[j] = chars[17];
++j;
break;

case '3': out[j] = chars[18];
++j;
break;

case '4': out[j] = chars[19];
++j;
break;

case '5': out[j] = chars[20];
++j;
break;

case '6': out[j] = chars[21];
++j;
break;

case '7': out[j] = chars[22];
++j;
break;

case '8': out[j] = chars[23];
++j;
break;

case '9': out[j] = chars[24];
++j;
break;

case ':': out[j] = chars[25];
++j;
break;

case ';': out[j] = chars[26];
++j;
break;

case '<': out[j] = chars[27];
++j;
break;

case '=': out[j] = chars[28];
++j;
break;

case '>': out[j] = chars[29];
++j;
break;

case '?': out[j] = chars[30];
++j;
break;

case '@': out[j] = chars[31];
++j;
break;

case 'A': out[j] = chars[32];
++j;
break;

case 'B': out[j] = chars[33];
++j;
break;

case 'C': out[j] = chars[34];
++j;
break;

case 'D': out[j] = chars[35];
++j;
break;

case 'E': out[j] = chars[36];
++j;
break;

case 'F': out[j] = chars[37];
++j;
break;

case 'G': out[j] = chars[38];
++j;
break;

case 'H': out[j] = chars[39];
++j;
break;

case 'I': out[j] = chars[40];
++j;
break;

case 'J': out[j] = chars[41];
++j;
break;

case 'K': out[j] = chars[42];
++j;
break;

case 'L': out[j] = chars[43];
++j;
break;

case 'M': out[j] = chars[44];
++j;
break;

case 'N': out[j] = chars[45];
++j;
break;

case 'O': out[j] = chars[46];
++j;
break;

case 'P': out[j] = chars[47];
++j;
break;

case 'Q': out[j] = chars[48];
++j;
break;

case 'R': out[j] = chars[49];
++j;
break;

case 'S': out[j] = chars[50];
++j;
break;

case 'T': out[j] = chars[51];
++j;
break;

case 'U': out[j] = chars[52];
++j;
break;

case 'V': out[j] = chars[53];
++j;
break;

case 'W': out[j] = chars[54];
++j;
break;

case 'X': out[j] = chars[55];
++j;
break;

case 'Y': out[j] = chars[56];
++j;
break;

case 'Z': out[j] = chars[57];
++j;
break;

case '[': out[j] = chars[58];
++j;
break;

case '\\': out[j] = chars[59];
++j;
break;

case ']': out[j] = chars[60];
++j;
break;

case '^': out[j] = chars[61];
++j;
break;

case '_': out[j] = chars[62];
++j;
break;

case '`': out[j] = chars[63];
++j;
break;

case 'a': out[j] = chars[64];
++j;
break;

case 'b': out[j] = chars[65];
++j;
break;

case 'c': out[j] = chars[66];
++j;
break;

case 'd': out[j] = chars[67];
++j;
break;

case 'e': out[j] = chars[68];
++j;
break;

case 'f': out[j] = chars[69];
++j;
break;

case 'g': out[j] = chars[70];
++j;
break;

case 'h': out[j] = chars[71];
++j;
break;

case 'i': out[j] = chars[72];
 &nb

#2 Guest_stay_*

Guest_stay_*
  • Guests

Posted 15 January 2006 - 05:11 AM

i can't see the use of this tool (except your training^^), however here's a question/tip:
1) permutation length=original length, so how can the permutation be 100 chars, when the length of the original is maximum 94?

2)
switch (permu[i])
					{
...
use a ascii function, so you can convert numbers to chararacters and simple use a loop instead of writing this all by hand :)

#3 Booster2ooo

Booster2ooo

    Sergeant

  • Members
  • 247 posts

Posted 15 January 2006 - 05:53 AM

I think it may be usefull for creating some kind of bruteforce dico ... no ?

#4 gunknown

gunknown

    Private First Class

  • Members
  • 32 posts

Posted 15 January 2006 - 07:57 AM

1) permutation length=original length, so how can the permutation be 100 chars, when the length of the original is maximum 94?

You have to differentiate between the integer variables size and length. Size is the amount of passed variables and length is the wanted length of the permutations. Try it yourself, it works without any problem.

use a ascii function, so you can convert numbers to chararacters and simple use a loop instead of writing this all by hand

Yes, you are right. I thought about something like that when I wrote the algorythm. Perhaps in v0.2 I will make the code more elegant :)

I think it may be usefull for creating some kind of bruteforce

Yes, perhaps you could create passwordlists...
I heard something about that some vulnerabilities are activated by certain character combinations. You can use this tool to generate such combinations for example.

//why is my sourcecode cut? When I previewed the post it was complete.

#5 linux_dude

linux_dude

    Staff Sergeant

  • Members
  • 343 posts

Posted 15 January 2006 - 10:26 AM

Um, wouldn't it be smarter to not care about what characters a user passes in?

Also, use recursion, you can do this in about 5 lines of coding.

#6 AdmiralB

AdmiralB

    Specialist

  • Sergeant Major
  • 338 posts

Posted 15 January 2006 - 06:28 PM

i think definately used for some sort of bruteforce dictionary attack by using this tool as a wordlist generator....but its gonna take awhile if u permuatate it...random useless words that probably won't be used as logins

#7 gunknown

gunknown

    Private First Class

  • Members
  • 32 posts

Posted 25 January 2006 - 09:30 AM

Um, wouldn't it be smarter to not care about what characters a user passes in?

Hmm, maybe you are right. If I didn't care about, I would have code this tool in a few lines. Mainly the long and ugly switch command wouldn't be neccessary.
But I think it can be usefull, and perhaps this is what the tool makes interessting, that you can generate permutations of arbitrary characters. So, perhaps you only want combinations with special characters (like !"$%&/()=?), or only numbers, or just lower case letters. Everything is possible :P

greets
gunknown

#8 nomorehateok

nomorehateok

    Private

  • Members
  • 3 posts

Posted 01 August 2012 - 03:30 AM

I need this tool but File has been removed
Can you please upload again





Also tagged with one or more of these keywords: tools, distributed