Compiling a program doesn’t protect it or necessarily hide the source. Take the following example C program. It serves no real life purpose and should never print anything to the console:
#include <stdio.h>
int main(void)
{
const char *password = "secretpassword";
const char *otherpassword = "othersecretpassword";
if(!strcmp(password, otherpassword))
{
printf("This will never get evaluated");
}
return 0;
}
To assemble the code using gcc -S test.c leaves test.s. The important point being that all strings remain intact:
(more…)
Tags: C, gcc, Linux, ls, reverse engineering, strings
Here’s a very brief example of how to use setuid() and setgid() functions in your C program.
int main(void)
{
int current_uid = getuid();
printf(”My UID is: %d. My GID is: %d\n”, current_uid, getgid());
system(”/usr/bin/id”);
if (setuid(0))
{
perror(”setuid”);
return 1;
}
//I am now root!
printf(”My UID is: %d. My GID is: %d\n”, getuid(), getgid());
system(”/usr/bin/id”);
//Time to drop back to regular user priviledges
setuid(current_uid);
printf(”My UID is: %d. My GID is: %d\n”, getuid(), getgid());
system(”/usr/bin/id”);
return 0;
}
The program above should be pretty self explainatory, now:
Tags: C, gcc, Linux, setgid, setuid, System
Further to post http://www.adamsinfo.com/multithreaded-tcp-proxy-tunnel-code/
I have received a report from a user experiencing the following error:
# gcc -Wall -g -O2 -o tcp_tun tcp_tun.c -lpthread
tcp_tun.c:44:37: error: getaddrinfo/getaddrinfo.h: No such file or directory
tcp_tun.c:45:37: error: getaddrinfo/getaddrinfo.c: No such file or directory
I think that this is a common error involving distros without getaddrinfo available. I have packaged up everything up with getaddrinfo and a configure/Makefile also. Please let me know your feedback.
Tags: C, gcc, Linux, tcp, tcp proxy, tcp tunnel
Further to my earlier article, I went ahead and developed this application. Here’s a beta!
File: tcp_tun.c
Version: 0.3-beta
Title: TCP reassembling client-server application
Date: 17 Aug 09
Author: Adam Palmer <adam [AT] adamsinfo [DOT] com>
URL: http://www.adamsinfo.com/
(more…)
Tags: C, code, debian, gcc, Linux, multithread, tcp, tcp proxy, tcp tunnel
Over the past week I’ve made a couple of hardware improvements, as well as building the majority of the software library, a TCP server and making a good start on a client.
The camera draws over 350mA@12V and there’s no reason why I need it permenantly on. I’ve connected one of the Phidget Kit’s outputs to a simple transistor/resistor/LED circuit, with a 12V supply passing into the transistor’s collector pin, through the transistor, relay input and resistor. Then I’ve connected the camera’s power over the relay’s output. The power on and off for the camera/LED are now through setting the board’s digital output 0 to 1 and 0 respectively. Power consumption with no movement has now dropped from 1.25A to just under 0.90A. I’ve also put all essential USB hardware on one usb hub and all optional hardware on another (USB to TTL adapters, sound adapter) on the other. The optional hub is also on a relay now on the opposite side of the robot, and this now reduces idle power consumption from 0.90A to about 0.50A which I’m happy with.
![]() |
![]() |
I’ve spent a while working on the software site of things. I’ve written a ‘library’ in C which interfaces with the various hardware that we’re interested in. The library provides a number of functions, I’ve listed the useful ones here, and they’re hopefully pretty self explainatory: (more…)
Tags: 12v, beej, C, camera, collector, cvoiceengine, digital output, LED, Linux robot, phidgets, phidgets sensor, port settings, power consumption, relay, resistor, software library, speech to text, struct, tcp server, termios, transistor, usb hub, usb to ttl
mknod is a powerful command with which you can create block or character special files. If you view the man page, you’ll see that you can use it to create block device links and character device links. If you don’t know what these are then don’t worry. The purpose of this tutorial is to explore the FIFO (First In First Out) feature.
A FIFO literally does what it says on the box. The first piece of data to go in is the first piece of data to go out.
The usage of the command is:
Usage: /bin/mknod [OPTION]… NAME TYPE [MAJOR MINOR]
Where MAJOR and MINOR are for the special devices mentioned above.
(more…)
Tags: /bin/mknod, beej, block, C, cat, character, device, echo, fifo, first in first out, Linux, major, man, man page, minor, mknod, shell script, special files