Thread: Argument Injection

  1. #1
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153

    Argument Injection

    I've been working on a project for a few months which creates 'random' logos via c. Everything is working great, and the logos are looking sharp. What I'm worried about is argument injection. The arguments (company name , slogan) originate from an html form and are then passed into c via a php exec() call. I may be in the wrong forum here, as any special c sanitizing seems like it must be done with php before the exec() call. I have tried injecting things like ";rm *png" and the program just treats them as literals and displays a logo using the text. I can't find any good tutorials on this, and am also wondering if there is some blanket c function to sanitize argv[i] before doing anything with it. Although at execution time it seems that danger has already passed.
    Ideas or links appreciated.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You're right in assuming it's not a C issue, generally speaking. If PHP's exec() is anything like POSIX's family of exec*() functions, the shell is not used at all, so shell injection is not possible.

    Now, if you pass argv[1] to system(), for example, you'll have a problem; but argv[1] is just the string ";rm *png", as you've discovered. By itself it's not dangerous: only if you pass it to a shell is there a problem.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Instead of passing the string on the command line, write it to a file and have the C program read it from that file. That way there is no possibility of anything nasty.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by brewbuck View Post
    Instead of passing the string on the command line, write it to a file and have the C program read it from that file. That way there is no possibility of anything nasty.
    Not true. Some other process can modify the file before it is read.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by grumpy View Post
    Not true. Some other process can modify the file before it is read.
    That is obviously a possibility but in this case the most you'd be able to accomplish is cause the renderer to render a string of your choice. That is nowhere near as scary as passing user-supplied data into exec()
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL Injection
    By Cr4zYPT in forum C Programming
    Replies: 7
    Last Post: 09-09-2011, 11:43 AM
  2. dll injection
    By mundaneblur in forum Windows Programming
    Replies: 0
    Last Post: 09-16-2010, 12:58 AM
  3. DLL Injection, Help please
    By AlexWu in forum C Programming
    Replies: 12
    Last Post: 05-05-2010, 08:50 PM
  4. DLL Injection
    By Lionel in forum Windows Programming
    Replies: 1
    Last Post: 07-24-2005, 05:18 PM