Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide text inside compiled C code?

Tags:

c

printf

I am not so familiar with the C language and compiling it in Linux but I have something to ask and hope you can assist.

I have this line of code that uses an installed command and its parameters to join domain. (see pic). After I run gcc join.c to compile it its created a file a.out. So far so good but when I run vim a.out to view to content of that file I see mypassword can be easily viewed by a simple text editor. (see second pic)

Is there anything I can do to avoid this when compiling my C code?

#include <stdio.h>
#include <unistd.h>

int main ()
{
        printf("Running 'net join' with the following parameters: \n");
        char *domain="mydomain";
        char *user="domainjoinuser";
        char *pass="mypassword";
        char *vastool="/opt/quest/bin/vastool";
        char *ou="OU=test,DC=mtdomain,DC=local";
        char unjoin[512];

        sprintf(unjoin,"/opt/quest/in/vastool -u %s -w '%s' unjoin -f",user,pass);

        printf("Domain: %s\n",domain);
        printf("User: %s\n",user);
        printf("-----------------\n");

        printf("Unjoin.............\n");
        system(unjoin);

        printf("Join................\n");
        execl("/opt/quest/bin/vastool", "vastool", "-u", user, "-w", pass, "join", "-c", "ou", "-f", domain, (char*)0);

}

source code viewed in vim

00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 3e 00 01 00 00 00  40 83 04 08 00 00 00 00  |..>.....@.......|
00000020  40 00 00 00 00 00 00 00  40 0a 00 00 00 00 00 00  |@.......@.......|
00000030  00 00 00 00 40 00 38 00  04 00 40 00 1c 00 1b 00  |[email protected]...@.....|
00000040  03 00 00 00 04 00 00 00  20 01 00 00 00 00 00 00  |........ .......|
00000050  20 81 04 08 00 00 00 00  20 81 04 08 00 00 00 00  | ....... .......|
00000060  1c 00 00 00 00 00 00 00  1c 00 00 00 00 00 00 00  |................|
00000070  01 00 00 00 00 00 00 00  01 00 00 00 05 00 00 00  |................|
00000080  20 01 00 00 00 00 00 00  20 81 04 08 00 00 00 00  | ....... .......|
00000090  20 81 04 08 00 00 00 00  b0 05 00 00 00 00 00 00  | ...............|
000000a0  b0 05 00 00 00 00 00 00  00 10 00 00 00 00 00 00  |................|
000000b0  01 00 00 00 06 00 00 00  e0 06 00 00 00 00 00 00  |................|
000000c0  e0 96 04 08 00 00 00 00  e0 96 04 08 00 00 00 00  |................|
000000d0  60 02 00 00 00 00 00 00  60 02 00 00 00 00 00 00  |`.......`.......|
000000e0  00 10 00 00 00 00 00 00  02 00 00 00 06 00 00 00  |................|
000000f0  24 08 00 00 00 00 00 00  24 98 04 08 00 00 00 00  |$.......$.......|
00000100  24 98 04 08 00 00 00 00  a0 00 00 00 00 00 00 00  |$...............|
00000110  a0 00 00 00 00 00 00 00  04 00 00 00 00 00 00 00  |................|
00000120  2f 6c 69 62 36 34 2f 6c  64 2d 6c 69 6e 75 78 2d  |/lib64/ld-linux-|
00000130  78 38 36 2d 36 34 2e 73  6f 2e 32 00 00 00 00 00  |x86-64.so.2.....|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 01 00 00 00  12 00 00 00 70 86 04 08  |............p...|
00000160  00 00 00 00 c0 01 00 00  00 00 00 00 13 00 00 00  |................|
00000170  12 00 00 00 80 86 04 08  00 00 00 00 a1 00 00 00  |................|
00000180  00 00 00 00 1a 00 00 00  12 00 00 00 90 86 04 08  |................|
00000190  00 00 00 00 8f 00 00 00  00 00 00 00 22 00 00 00  |............"...|
000001a0  12 00 00 00 a0 86 04 08  00 00 00 00 61 00 00 00  |............a...|
000001b0  00 00 00 00 29 00 00 00  12 00 00 00 b0 86 04 08  |....)...........|
000001c0  00 00 00 00 b0 01 00 00  00 00 00 00 2f 00 00 00  |............/...|
000001d0  12 00 0c 00 80 86 04 08  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 35 00 00 00  20 00 00 00 00 00 00 00  |....5... .......|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 5f 5f 6c  |.............__l|
00000200  69 62 63 5f 73 74 61 72  74 5f 6d 61 69 6e 00 70  |ibc_start_main.p|
00000210  72 69 6e 74 66 00 73 70  72 69 6e 74 66 00 73 79  |rintf.sprintf.sy|
00000220  73 74 65 6d 00 65 78 65  63 6c 00 5f 69 6e 69 74  |stem.execl._init|
00000230  00 5f 5f 67 6d 6f 6e 5f  73 74 61 72 74 5f 5f 00  |.__gmon_start__.|
00000240  6c 69 62 63 2e 73 6f 2e  36 00 00 00 04 00 00 00  |libc.so.6.......|
00000250  08 00 00 00 06 00 00 00  04 00 00 00 03 00 00 00  |................|
00000260  07 00 00 00 00 00 00 00  00 00 00 00 01 00 00 00  |................|
00000270  02 00 00 00 00 00 00 00  00 00 00 00 05 00 00 00  |................|
00000280  00 00 00 00 f8 98 04 08  00 00 00 00 07 00 00 00  |................|
00000290  01 00 00 00 00 00 00 00  00 00 00 00 00 99 04 08  |................|
000002a0  00 00 00 00 07 00 00 00  02 00 00 00 00 00 00 00  |................|
000002b0  00 00 00 00 08 99 04 08  00 00 00 00 07 00 00 00  |................|
000002c0  03 00 00 00 00 00 00 00  00 00 00 00 10 99 04 08  |................|
000002d0  00 00 00 00 07 00 00 00  04 00 00 00 00 00 00 00  |................|
000002e0  00 00 00 00 18 99 04 08  00 00 00 00 07 00 00 00  |................|
000002f0  05 00 00 00 00 00 00 00  00 00 00 00 20 99 04 08  |............ ...|
00000300  00 00 00 00 07 00 00 00  06 00 00 00 00 00 00 00  |................|
00000310  00 00 00 00 28 99 04 08  00 00 00 00 06 00 00 00  |....(...........|
00000320  07 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000330  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000340  31 ed 49 89 d1 5e 48 89  e2 48 83 e4 f0 50 54 49  |1.I..^H..H...PTI|
00000350  c7 c0 90 85 04 08 48 c7  c1 00 85 04 08 48 c7 c7  |......H......H..|
00000360  6c 83 04 08 e8 07 03 00  00 f4 66 90 55 48 89 e5  |l.........f.UH..|
00000370  48 81 ec 30 02 00 00 48  8d 05 66 13 00 00 48 89  |H..0...H..f...H.|
00000380  c7 b8 00 00 00 00 e8 f5  02 00 00 48 8d 05 86 13  |...........H....|
00000390  00 00 48 89 45 f8 48 8d  05 84 13 00 00 48 89 45  |..H.E.H......H.E|
000003a0  f0 48 8d 05 88 13 00 00  48 89 45 e8 48 8d 05 88  |.H......H.E.H...|
000003b0  13 00 00 48 89 45 e0 48  8d 05 94 13 00 00 48 89  |...H.E.H......H.|
000003c0  45 d8 48 8b 45 e8 49 89  c3 48 8b 45 f0 49 89 c2  |E.H.E.I..H.E.I..|
000003d0  48 8d 05 98 13 00 00 48  89 c6 48 8d 85 d8 fd ff  |H......H..H.....|
000003e0  ff 48 89 c7 4c 89 d2 4c  89 d9 b8 00 00 00 00 e8  |.H..L..L........|
000003f0  9c 02 00 00 48 8b 45 f8  48 89 c6 48 8d 05 9b 13  |....H.E.H..H....|
00000400  00 00 48 89 c7 b8 00 00  00 00 e8 71 02 00 00 48  |..H........q...H|
00000410  8b 45 f0 48 89 c6 48 8d  05 8c 13 00 00 48 89 c7  |.E.H..H......H..|
00000420  b8 00 00 00 00 e8 56 02  00 00 48 8d 05 82 13 00  |......V...H.....|
00000430  00 48 89 c7 b8 00 00 00  00 e8 42 02 00 00 48 8d  |.H........B...H.|
00000440  05 81 13 00 00 48 89 c7  b8 00 00 00 00 e8 2e 02  |.....H..........|
00000450  00 00 48 8d 85 d8 fd ff  ff 48 89 c7 b8 00 00 00  |..H......H......|
00000460  00 e8 3a 02 00 00 48 8d  05 6e 13 00 00 48 89 c7  |..:...H..n...H..|
00000470  b8 00 00 00 00 e8 06 02  00 00 48 b8 00 00 00 00  |..........H.....|
00000480  00 00 00 00 50 48 8b 45  f8 50 48 8d 05 90 13 00  |....PH.E.PH.....|
00000490  00 50 48 8d 05 85 13 00  00 50 48 8d 05 7a 13 00  |.PH......PH..z..|
000004a0  00 50 48 8d 05 6d 13 00  00 50 48 8b 45 e8 49 89  |.PH..m...PH.E.I.|
000004b0  c1 48 8d 05 5b 13 00 00  49 89 c0 48 8b 45 f0 49  |.H..[...I..H.E.I|
000004c0  89 c3 48 8d 05 47 13 00  00 49 89 c2 48 8d 05 35  |..H..G...I..H..5|
000004d0  13 00 00 48 89 c6 48 8d  05 14 13 00 00 48 89 c7  |...H..H......H..|
000004e0  4c 89 d2 4c 89 d9 b8 00  00 00 00 e8 c0 01 00 00  |L..L............|
000004f0  48 83 c4 30 c9 c3 00 00  00 00 00 00 00 00 00 00  |H..0............|
00000500  48 89 6c 24 d8 4c 89 64  24 e0 48 8d 2d 4f 01 00  |H.l$.L.d$.H.-O..|
00000510  00 4c 8d 25 48 01 00 00  48 89 5c 24 d0 4c 89 6c  |.L.%H...H.\$.L.l|
00000520  24 e8 4c 89 74 24 f0 4c  89 7c 24 f8 48 83 ec 38  |$.L.t$.L.|$.H..8|
00000530  4c 29 e5 41 89 ff 49 89  f6 48 c1 fd 03 49 89 d5  |L).A..I..H...I..|
00000540  31 db e8 d9 00 00 00 48  85 ed 74 1a 0f 1f 40 00  |1......H..t...@.|
00000550  4c 89 ea 4c 89 f6 44 89  ff 41 ff 14 dc 48 83 c3  |L..L..D..A...H..|
00000560  01 48 39 eb 75 ea 48 8b  5c 24 08 48 8b 6c 24 10  |.H9.u.H.\$.H.l$.|
00000570  4c 8b 64 24 18 4c 8b 6c  24 20 4c 8b 74 24 28 4c  |L.d$.L.l$ L.t$(L|
00000580  8b 7c 24 30 48 83 c4 38  c3 0f 1f 80 00 00 00 00  |.|$0H..8........|
00000590  f3 c3 00 00 01 00 02 00  14 00 00 00 00 00 00 00  |................|
000005a0  01 7a 52 00 01 78 10 01  1b 0c 07 08 90 01 07 10  |.zR..x..........|
000005b0  14 00 00 00 1c 00 00 00  88 fd ff ff 2a 00 00 00  |............*...|
000005c0  00 00 00 00 00 00 00 00  14 00 00 00 00 00 00 00  |................|
000005d0  01 7a 52 00 01 78 10 01  1b 0c 07 08 90 01 00 00  |.zR..x..........|
000005e0  24 00 00 00 1c 00 00 00  18 ff ff ff 89 00 00 00  |$...............|
000005f0  00 4a 86 06 8c 05 66 0e  40 83 07 8d 04 8e 03 8f  |.J....f.@.......|
00000600  02 02 58 0e 08 00 00 00  14 00 00 00 44 00 00 00  |..X.........D...|
00000610  80 ff ff ff 02 00 00 00  00 00 00 00 00 00 00 00  |................|
00000620  48 83 ec 08 48 8b 05 fd  12 00 00 48 85 c0 74 05  |H...H......H..t.|
00000630  e8 cb 79 fb f7 48 83 c4  08 c3 00 00 48 83 ec 08  |..y..H......H...|
00000640  48 83 c4 08 c3 00 00 00  00 00 00 00 00 00 00 00  |H...............|
00000650  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000660  ff 35 82 12 00 00 ff 25  84 12 00 00 00 00 00 00  |.5.....%........|
00000670  ff 25 82 12 00 00 68 00  00 00 00 e9 e0 ff ff ff  |.%....h.........|
00000680  ff 25 7a 12 00 00 68 08  00 00 00 e9 d0 ff ff ff  |.%z...h.........|
00000690  ff 25 72 12 00 00 68 10  00 00 00 e9 c0 ff ff ff  |.%r...h.........|
000006a0  ff 25 6a 12 00 00 68 18  00 00 00 e9 b0 ff ff ff  |.%j...h.........|
000006b0  ff 25 62 12 00 00 68 20  00 00 00 e9 a0 ff ff ff  |.%b...h ........|
000006c0  ff 25 5a 12 00 00 68 28  00 00 00 e9 90 ff ff ff  |.%Z...h(........|
000006d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000006e0  00 00 00 00 52 75 6e 6e  69 6e 67 20 27 6e 65 74  |....Running 'net|
000006f0  20 6a 6f 69 6e 27 20 77  69 74 68 20 74 68 65 20  | join' with the |
00000700  66 6f 6c 6c 6f 77 69 6e  67 20 70 61 72 61 6d 65  |following parame|
00000710  74 65 72 73 3a 20 0a 00  6d 79 64 6f 6d 61 69 6e  |ters: ..mydomain|
00000720  00 64 6f 6d 61 69 6e 6a  6f 69 6e 75 73 65 72 00  |.domainjoinuser.|
00000730  6d 79 70 61 73 73 77 6f  72 64 00 2f 6f 70 74 2f  |mypassword./opt/|
00000740  71 75 65 73 74 2f 62 69  6e 2f 76 61 73 74 6f 6f  |quest/bin/vastoo|
00000750  6c 00 4f 55 3d 74 65 73  74 2c 44 43 3d 6d 74 64  |l.OU=test,DC=mtd|
00000760  6f 6d 61 69 6e 2c 44 43  3d 6c 6f 63 61 6c 00 2f  |omain,DC=local./|
00000770  6f 70 74 2f 71 75 65 73  74 2f 69 6e 2f 76 61 73  |opt/quest/in/vas|
00000780  74 6f 6f 6c 20 2d 75 20  25 73 20 2d 77 20 27 25  |tool -u %s -w '%|
00000790  73 27 20 75 6e 6a 6f 69  6e 20 2d 66 00 44 6f 6d  |s' unjoin -f.Dom|
000007a0  61 69 6e 3a 20 25 73 0a  00 55 73 65 72 3a 20 25  |ain: %s..User: %|
000007b0  73 0a 00 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |s..-------------|
000007c0  2d 2d 2d 2d 0a 00 55 6e  6a 6f 69 6e 2e 2e 2e 2e  |----..Unjoin....|
000007d0  2e 2e 2e 2e 2e 2e 2e 2e  2e 0a 00 4a 6f 69 6e 2e  |...........Join.|
000007e0  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 0a  |................|
000007f0  00 2f 6f 70 74 2f 71 75  65 73 74 2f 62 69 6e 2f  |./opt/quest/bin/|
00000800  76 61 73 74 6f 6f 6c 00  76 61 73 74 6f 6f 6c 00  |vastool.vastool.|
00000810  2d 75 00 2d 77 00 6a 6f  69 6e 00 2d 63 00 6f 75  |-u.-w.join.-c.ou|
00000820  00 2d 66 00 01 00 00 00  00 00 00 00 44 00 00 00  |.-f.........D...|
00000830  00 00 00 00 04 00 00 00  00 00 00 00 4c 82 04 08  |............L...|
...

binary file viewed in vim

like image 816
Asaf Magen Avatar asked Sep 24 '13 15:09

Asaf Magen


1 Answers

Is there anything i can do to avoid this when compiling my C code?

The only thing you can do is to not hard-code the password or any sensitive information into your C program: even if you encrypt this sensitive information in one way or the other, either the decryption key would need to be provided at runtime by a user running your program, or the info could be decrypted by a sufficiently motivated person. You might as well prompt the user for the password.

Note that any other form of hiding would be a mere obfuscation - a small obstacle on the way of a user who is trying to access your secret information. It may deter a few "script kiddies", but it would fall to the first knowledgeable user.

like image 117
Sergey Kalinichenko Avatar answered Sep 20 '22 09:09

Sergey Kalinichenko