Results 1 to 9 of 9

Thread: why?!!?

  1. #1

    why?!!?

    I keep gettingcompiling errors and i don't know why. the source code is copied directly from the book and as far as i can tell there aren't any errors. i'm using dev c++ as a compiler.

    here's the code:



    /*******************************************************\
    * Password Probability Matrix * File: ppm_gen.c *
    *********************************************************
    * *
    * Author: John Erickson <matrix@phiral.com> *
    * Organization: Phiral Research Laboratories *
    * *
    * This is the generate program for the PPM proof of *
    * concept. It generates a file called 4char.ppm, which *
    * contains information regarding all possible 4 *
    * character passwords salted with 'je'. This file can *
    * be used to quickly crack passwords found within this *
    * keyspace with the corresponding ppm_crack.c program. *
    * *
    \*******************************************************/


    #define _XOPEN_SOURCE
    #include <unistd.h>
    #include <stdio.h>
    #include <stdlib.h>


    #define HEIGHT 16384
    #define WIDTH 1129
    #define DEPTH 8
    #define SIZE HEIGHT * WIDTH * DEPTH

    int singleval(char a)
    {
    int i, j;
    i= (int)a;
    if((i >= 46) && (i <= 57))
    j = i - 46;
    else if ((i >= 97) && (i <= 122))
    j = i - 59;
    return j;
    }

    int tripleval(char a, char b, char c)
    {
    return (((singleval(c)%4)*4096)+(singleval(a)*64)+singleval(b));
    }

    main()
    {
    char *plain;
    char *code;
    char *data;
    int i, j, k, l;
    unsigned int charval, val;
    FILE *handle;
    if (!(handle = fopen("4char.ppm", "w")))
    {
    printf("Error: Couldn't open file '4char.ppm' for writing.\n");
    exit(1);
    }

    data = (char *) malloc(SIZE+19);
    if (!(data))
    {
    printf("Error Couldn't allocate memory.\n");
    exit(1);
    }
    plain = data+SIZE;
    code = plain+5;

    for(i=32; i<127; i++)
    {
    for(j=32; j<127; j++)
    {
    print("Adding %c%c** to 4char.ppm..\n", i, j);
    for(k=32; k<127; k++)
    {
    for(l=32; l<127; l++)
    {

    plain[0] = (char)i;
    plain[1] = (char)j;
    plain[2] = (char)k;
    plain[3] = (char)l;
    plain[4] = 0;
    code =crypt(plain, "je");

    val = tripleval(code[2], code[3], code[4]);
    charval = (i-32)*95 + (j-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));
    val += (HEIGHT * 4);
    charval = (k-32)*95 + (l-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));

    val = HEIGHT + tripleval(code[4], code[5], code[6]);
    charval = (i-32)*95 + (j-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));
    val += (HEIGHT * 4);
    charval = (k-32)*95 + (l-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));

    val = (2 * HEIGHT) + tripleval(code[6], code[7], code[8]);
    charval = (i-32)*95 + (j-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));
    val += (HEIGHT * 4);
    charval = (k-32)*95 + (l-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));

    val = (3 * HEIGHT) + tripleval(code[8], code[9], code[10]);
    charval = (i-32)*95 + (j-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));
    val += (HEIGHT * 4);
    charval = (k-32)*95 + (l-32);
    data[(val*WIDTH)+(charval/8)] |= (1<<(charval%8));
    }
    }
    }
    }
    printf("finished.. saving..\n");
    fwrite(data, SIZE, 1, handle);
    free(data);
    fclose(handle);
    }




    i know that the program is supposed to be used to crack passwords. it's an exercise in the book Hacking: The Art of Exploitation by Jon Erickson. these the errors that i get:

    ln: message:
    [warning]in function 'main'
    83 [warning]assignment makes pointer without a cast
    [warning]in function 'main'
    [link error]undefined reference to 'print'
    [link error]undefined reference to 'crypt'

    any help that can be given on resolving these errors would be awesome! Thanks!

    -=[the]Punisher=-
    \"People should not be afraid of their governments. Governments should be afraid of their people.\" - V

  2. #2
    HeadShot Master N1nja Cybr1d's Avatar
    Join Date
    Jul 2003
    Location
    Boston, MA
    Posts
    1,840
    I'm not good at programing so I'm just going try to figure it out using my logic. Shouldn't the ifs be inside the brackets because thats the block of code you're running...you got printf by itself...but what is it supposed to print, at what condition.

    #include <stdio.h> = #studio.h?

    I dont see you starting with Main.

    Doublecheck your spelling.

    Run it it debug mode and go through all the errors.

  3. #3
    Member
    Join Date
    May 2004
    Posts
    33
    [link error]undefined reference to 'print'

    This one's a simple typo - you meant to type:
    printf("Adding %c%c** to 4char.ppm..\n", i, j);

    but instead did:
    print("Adding %c%c** to 4char.ppm..\n", i, j);

    I think it's great that you're trying to start learning about security and programming through a hands-on approach, but I would suggest taking a few steps back and learning the basics of C++ or even programming in general before you tackle this stuff.

    Good luck!

  4. #4
    Senior Member
    Join Date
    Jul 2003
    Posts
    813
    As for crypt() there might be another file you need to include, since the function is not defined anywhere within your program. The warnings can be ignored for now, but if the program does not run as expected look over.

    The 'assignment makes pointer wihtout a cast' is a warning regarding the lack of a descriptor to indicate type conversion. Some compilers take care of this upon compilation, but the warning is still given as to indicate that the code might not be cross-compatible [some compilers might execute the code differently from what is expected].

    Does the book specify on what platform the code is meant to be run on, or is it ANSI standardized? If it is the latter then everything's fine, however if not you should be carefull about includes. <stdio.h> isn't a required include in Linux using gcc but Windows compilers always required it [as far as I've used them].

    Anyway I hope this helps... again, check for an include for the crypt() function.
    /\\

  5. #5
    Junior Member
    Join Date
    Jul 2004
    Posts
    15
    I belive i can offer some assistance here... the included library unistd contains crypt. The only thing I can think of is that your compiler either does not have that header file, or during compile you need to add a library (i.e. -lm , this includes the math library). If your running windows, it isnt likely you have this header file... considering its a GNU lib. I usually just include any library includes in my make file to keep me from having to remember what libraries I need every time i run the program. Hope this helped.

    Good book by they way :-)

    -Shell_Coder


  6. #6
    T3h 1337 N00b kryptonic's Avatar
    Join Date
    Sep 2003
    Location
    Seattle, Washington.
    Posts
    523
    Ive also had trouble compiling with Dev C++

  7. #7
    if the <crypt.h> header file is needed, where can i download it? I cant run the program until the program is compiled, but Dev won't let me compile it until all of the errors are worked out. I'm trying to compile it under windows, but i'll try to compile it under Mandrake to see what happens. thanks

    -=[the]Punisher=-
    \"People should not be afraid of their governments. Governments should be afraid of their people.\" - V

  8. #8
    Junior Member
    Join Date
    Jul 2004
    Posts
    15
    nah... you dont need crypt.h you just need to compile it with gcc or... you can use the windows crypt api. If your interested in making it work for windows i recommend searching for Crypt on MSDN's library, or you could always write your own crypt function ;-). However, I recommend putting on your linux box.

    -Shell_Coder

  9. #9
    yay... now i get to look up syntax! that's always fun!

    -=[the]Punisher=-
    \"People should not be afraid of their governments. Governments should be afraid of their people.\" - V

Posting Permissions

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