Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 31st, 2005, 7:08 PM   #1
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
My brute forcer in C

This is a program I wrote a while ago and posted at http://lineman.net/node/520 . This is the updated and final version. Given the character set "set" and the size of the array "gss" (in this case 3) it will print all the possible values. She is pretty fast, just prone to stack overflows because it's recursive. Enjoy.
/*
	Copyright 2005(c) Ian Treyball
    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

	This program is provided "as is".
	The author takes no responsibility for anything done with it.
	_caution_ If the program recurses too deeply you can have a stack overflow.
*/
#include <stdio.h>
#include <math.h>
#include <time.h>

static void incr(const unsigned short int pos);
static const char set[] = {
	'a', 'b', 'c', 'd', 'e', 'f',
	'g', 'h', 'i', 'j', 'k', 'l',
	'm', 'n', 'o', 'p', 'q', 'r',
	's', 't', 'u', 'v', 'w', 'x',
	'y', 'z', '$', '!', '%', '*'
};
static char gss[3];
static unsigned long int cnt = 0;
static FILE *rslts;

int main(int argc, char **argv) {
	memset(&gss, '\0', sizeof(gss));
	rslts = fopen("results.txt", "w");
	const unsigned int pssbl = pow(sizeof(set), sizeof(gss));
	while(cnt < pssbl)
		incr(0);
	if(fclose(rslts) != 0) {
		fprintf(stderr, "%s", "error closing file");
		return -1;
	}
	printf("%s completed successfully\n", argv[0]);
	return 0;
}

static void incr(const unsigned short int pos) {
	cnt++;
	if(gss[pos] != '\0') {
	    static unsigned short int n;
		for(n = 0; n < sizeof(set); ++n) {
			if(gss[pos] == set[n]) {
				gss[pos] = set[n + 1];
				fputs(gss, rslts);
				fputc('\n', rslts);
				break;
			}
		}
		static unsigned short int i;
		for(i = 0; i < sizeof(gss); ++i) {
			if(gss[i] != set[sizeof(set) - 1]) {
				incr(i);
				break;
			} else {
				gss[i] = set[0];
			}
		}
	} else {
		gss[pos] = set[0];
		fputs(gss, rslts);
		fputc('\n', rslts);
	}
	return;
}
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Aug 31st, 2005, 7:50 PM   #2
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 574
Rep Power: 5 Benoit is on a distinguished road
So this computes every possible combination of letters and $, *, ! in a 3 character word?

EDIT: Oh...You explained it in your first post
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Sep 5th, 2005, 6:08 PM   #3
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Hacking - Do not discuss hacking on Programming Forums. This includes, but is not limited to discussion making/using hacks for video games, writing/using brute-force to gain passwords, or gaining unauthorized access to a machine. Security can be discussed, but from a constructive standpoint. Whether or not your posts involving security discussion are constructive or not are based on the staff's discretion, and if the staff deems that your post is not from a constructive point of view then appropriate action will be taken. This rule will be inforced on a case by case basis.
Looks like I already broke a rule, sorry. Although I did not write this with the intention of password cracking. I think it's a legitimet program, but if any mod/admin disagrees, then I will not be offended if it's removed.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Sep 5th, 2005, 8:08 PM   #4
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
I tried to compile and run it, but it had some errors. Sounds cool though.
Navid is offline   Reply With Quote
Old Sep 5th, 2005, 9:16 PM   #5
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by Navid
I tried to compile and run it, but it had some errors. Sounds cool though.
What errors? I compiled with gcc 3.3.1 (using Dev-C++ 4.9.9.0) and it works. What compiler are you using? Thanks.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Sep 5th, 2005, 10:14 PM   #6
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
I'm using Dev-C++ 4, these are the errors

38 main.c parse error before `const'
39 main.c `pssbl' undeclared (first use in this function)
61 main.c parse error before `static'
62 main.c `i' undeclared (first use in this function)
Navid is offline   Reply With Quote
Old Sep 6th, 2005, 2:10 AM   #7
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Yes but which compiler are you using. Dev-C++ is an IDE, it uses another compiler such as GCC.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Sep 6th, 2005, 7:05 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Out of the box, Dev C++ would use gcc for C and g++ for C++, the mingw variety, I believe. Some errors might be compiler specific, particularly the one about "i".

EDIT: Results with VC++ 6.0

a) Requires the inclusion of string.h or memory.h for memset.
b) VC++ 6.0 compiling C doesn't allow the declaration of variables "down in the code", after instructions have been generated. This affects pssbl and also "i", in the incr function.
c) assigning the return of "pow" to pssbl will generate a warning unless cast.

I didn't do it in Dev C++, but this covers every error Navid mentions, and adds one (memset).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers

Last edited by DaWei; Sep 6th, 2005 at 7:23 AM.
DaWei is offline   Reply With Quote
Old Sep 6th, 2005, 9:52 PM   #9
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Okay, so I lied, because then that must not be the final version. I'm posted some revised code.

/*
	Copyright 2005(c) Ian Treyball
    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

	This program is provided "as is".
	The author takes no responsibility for anything done with it.
	_caution_ If the program recurses too deeply you can have a stack overflow.
*/
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>

static void incr(const unsigned short int pos);
static const char set[] = {
	'a', 'b', 'c', 'd', 'e', 'f',
	'g', 'h', 'i', 'j', 'k', 'l',
	'm', 'n', 'o', 'p', 'q', 'r',
	's', 't', 'u', 'v', 'w', 'x',
	'y', 'z'
};
static char gss[4]; // for longer words, change the number here
static unsigned long int cnt = 0;
static unsigned int i = 0, n = 0;
static FILE *rslts;

int main(int argc, char **argv) {
	memset(&gss, '\0', sizeof(gss));
	rslts = fopen("results.txt", "w");
	// this seems reasonable for computing an okay size buffer.
	const size_t BUF_SIZE = sizeof(gss)/2 > 1?1024 * (sizeof(gss)/2) : 2048;
	char *const buf = (char *)malloc(BUF_SIZE);
	setvbuf(rslts, buf, _IOFBF, BUF_SIZE);
	// thanks to DaWei for bringing this former uncasted call to my attention.
	const unsigned int pssbl = (unsigned int)pow(sizeof(set), sizeof(gss));
	while(cnt < pssbl) {
		incr(0);
	}
	// responsible for flushing rslts, too
	if(fclose(rslts) != 0) {
		fprintf(stderr, "%s", "error closing file");
		return -1;
	}
	free(buf);
	printf("%s was successful\n", argv[0]);
	return 0;
}
/*
 * The heart of this program. Each call to this produces
 * the next value assigned to gss[] and writes it out to rslts.
 */
static void incr(const unsigned short int pos) {
	cnt++;
	if(gss[pos] != '\0') {
		for(n = 0; n < sizeof(set); ++n) {
			if(gss[pos] == set[n]) {
				gss[pos] = set[n + 1];
				fputs(gss, rslts);
				fputc('\n', rslts);
				break;
			}
		}
		for(i = 0; i < sizeof(gss); ++i) {
			if(gss[i] != set[sizeof(set) - 1]) {
				incr(i);
				break;
			} else {
				gss[i] = set[0];
			}
		}
	} else {
		gss[pos] = set[0];
		fputs(gss, rslts);
		fputc('\n', rslts);
	}
	return;
}
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC