Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (13) </ 1 2 3 [4] 5 6 7 8 9 ... >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: C question, loops< Next Oldest | Next Newest >
humpty Offline





Group: Members
Posts: 655
Joined: Sep. 2005
Posted: Jan. 13 2008,16:05 QUOTE

yeh, wdef's code is somewhat similar to some c code i used before to generate strings;
just change MAX to 30 and the 'check' routine.
Code Sample

#include <stdio.h>

#define MAX 4

int check (char *s)
{
printf ("%s\n", s);
if (!strcmp (s, "help")) return (1);
return (0);
}
//--------------------------------------
char s[MAX+1];

int try_again (int pos)
{
char c;

s[pos+1]='\0';

for (c='a'; c<'z'+1; c++)
{
 s[pos] = c;
 if (check (s)) return(1); //success!

 if (pos == MAX-1) continue;
 if (try_again (pos+1)) return(1);
}
return (0);
}
//--------------------------------------
int main ()
{
if (try_again (0)) printf ("cracked :)\n");
else               printf ("failed :(\n");
}


the trick is to recurse, but to also use a global var so you don't blow the stack memory!
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Jan. 13 2008,16:31 QUOTE

I don't understand this part:

if (!strcmp (s, "help")) return (1);

So if the string is not found, return success?


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Jan. 13 2008,16:33 QUOTE

Ah - that's the perversity of C

the strings are equal when strcmp fails!
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Jan. 13 2008,16:36 QUOTE

Agreed.. Weird indeed, considering the function is "compare strings".

How about a modification to the perl code similar to dd, that when you receive SIGUSR1 you output where you are going?


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Jan. 13 2008,16:37 QUOTE

There's one problem with openssl for this brute forcing purpose:  it will output binary garbage and return success when given certain incorrect passphrases.  So it appears to decrypt when it doesn't.

As a workaround, I've just edited the example above so it runs cat on the outputted file - it it isn't text, cat will return 1 and the program won't exit.  That should get rid of false positives (I think).
Back to top
Profile PM 
64 replies since Jan. 12 2008,13:35 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (13) </ 1 2 3 [4] 5 6 7 8 9 ... >/
reply to topic new topic new poll
Quick Reply: C question

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code