473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

this code should chroot and exec program but fails

/************************************************** ***
*** chrexec.c ***
*This shit can be called from root or from any user (in that case executable
* should have 06755 permisions) and should chroot and exec program
* (specified in command line parameter) in general, but it doesn`t.
* ************************************************** **/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

#define VALIDATE(f,err) \
if (f == -1)\
{\
perror(err);\
exit (-1);\
}

int main(int args, char *argv[])
{
int i;
for (i = 0; i < args; i++)
{
fprintf(stderr, "param %02d: %s\n", i, argv[i]);
}
int initialUID = getuid();
int initialGID = getgid();
fprintf(stderr, "initial UID: %d initial GID: %d\n", initialUID, initialGID);

VALIDATE(setuid(0),"setuid")
VALIDATE(setgid(0),"setgid")

fprintf(stderr, "chrooting to .\n");
VALIDATE(chroot("."),"chroot")
VALIDATE(chdir("/"),"chdir")

DIR *curr = opendir(".");
if (!curr)
{
perror("opendir");
exit(-1);
}
struct dirent *dir;
fprintf(stderr, "Files in \".\":\n");
while (dir = readdir(curr))
{
fprintf(stderr, ">> %s\n", dir->d_name);
}
fprintf(stderr, "No more files in \".\"\n");
VALIDATE(setgid(initialGID),"setgid")
VALIDATE(setuid(initialUID),"setuid")
VALIDATE(execv(argv[1], &argv[1]),"execv")
// execv: No such file or directory in most cases
return 0;
}
/************************************************** *****
* "chrexec" works if do not perform "chroot" call, and if "." (current dir) is "/".
* With chrexec I try to call another executable in "." directory (and even list
* files to show that this executable really exist in ".")
* That`s my first experience of using chroot, can anyone show me mistake?
************************************************** ******/
Apr 13 '07 #1
1 2076
sorry code was working, I just forgot to carry out some libs to new chroot...
Apr 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jimmy Jim | last post by:
Hey all, quick question to see if anyone has any ideas. I have an object: $special = new special; Let's say I have a function: class special { function outputtext() { return "test";
8
by: Stefan Seefeld | last post by:
hi there, I have trouble running some python code with 'exec': t.py contains: class Foo: pass class Bar: f = Foo From a python shell I do:
5
by: Carlos Moreno | last post by:
I just noticed that from a C or C++ program using libpq or libpq++, I can send *one* command that contains several SQL statements separated by semicolon. Something like: PgDatabase db (" .......
6
by: Gordowey | last post by:
Where can I find this DIV effect. go to: http://www.amazon.com Put mouse over the text "See All 32 Product Categories" (Top-Middle)..it will open a window with a cool effect... does anyone...
1
by: ashore | last post by:
Under Win32/Vista, PHP 5, I have a batch of files to convert and I'm trying to script that in PHP. The following fails silently - while the hand-entered version - sans the escapes of course -...
12
by: gregpinero | last post by:
This wiki page suggests using a chroot jail to sandbox Python, but wouldn't running something like this in your sandboxed Python instance still break you out of the chroot jail: os.execle...
8
by: John Henry | last post by:
How do I determine is something a function? For instance, I don't want to relying on exceptions below: def f1(): print "In f1" def f3(): print "In f3"
4
by: support\.intranet | last post by:
Hello! I'm writing a small script and I need to call the os.chroot function. The problem is, a few lines below I need to call a program in /usr/bin. Is there a way to exit from the chroot, or to...
9
by: Emanuele D'Arrigo | last post by:
I noticed that this issue has been discussed in this newsgroup periodically over the years and I seem to understand that - comprehensive- safe/restricted execution of untrusted code in python is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.