• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Search | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

Signal handling help

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More

View previous topic :: View next topic  
Author Message
zzddk
Just Arrived
Just Arrived


Joined: 14 Apr 2010
Posts: 0


Offline

PostPosted: Wed Apr 14, 2010 8:59 pm    Post subject: Signal handling help Reply with quote

hey can someone help me out. I'm trying to figure out the vulnerability of this program. My guess was to use the handle_signal method and change to value of cmdbuf so I will be able to run my own script. Any help is appreciated.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>

char cmdbuf[128] = "echo interrupt signal caught, terminating ";
char *progname;

/*
 * Handle a ^C keyboard interrupt in case the program is running
 * too long and the user terminates.
 */
void handle_signal(int sig)
{
  int len = sizeof(cmdbuf) - (strlen(cmdbuf) + 1);
  if (strlen(progname) > len)
    progname[len] = '\0';
  strcat(cmdbuf, progname);

  system(cmdbuf);
  exit(1);
}

void usage()
{
  printf("%s <n> where 0 < n <= 5.000\n", progname);
  exit(1);
}

/*
 * The program takes one argument line parameter n (which has to be a
 * positive integer input parameter) and then prints out the first n
 * prime numbers.
 */
int main(int argc, char **argv)
{
  struct sigaction sa;
  int cnt, N, found;
  unsigned long candidate, divisor;

  gid_t egid = getegid();
  setregid(egid, egid);

  /* set up signal handling */
  memset(&sa, sizeof(struct sigaction), 0);
  sa.sa_handler = handle_signal;
  sigaction(SIGINT, &sa, NULL);


  /* process argument */
  progname = argv[0];
  if (argc != 2)
    usage();
  N = strtol(argv[1], NULL, 10);
  if ((N <= 0) || (N > 5000))
    usage();


  /* calculate prime numbers -- simple sieve */
  candidate = 1;
  for (cnt = 0; cnt < N; ++cnt) {

    for (;;) {
      found = 1;
      divisor = 2;
      candidate += 1;

      while (divisor <= candidate/2) {
   if ((candidate % divisor) == 0) {
     found = 0;
     break;
   }
   else
     ++divisor;
      }
      if (found)
   break;
    }
    printf("%ld\n", candidate);
  }
 
  return 0;
}


Moderator note: edited to add code tags - capi
Back to top
View user's profile Send private message
rvdwesten
Just Arrived
Just Arrived


Joined: 31 Dec 2008
Posts: 0
Location: Breda, The Netherlands

Offline

PostPosted: Fri Jul 23, 2010 2:44 pm    Post subject: Reply with quote

Code:

strcat(cmdbuf, progname);

system(cmdbuf);


Says enough when you see

Code:

progname = argv[0];
Back to top
View user's profile Send private message MSN Messenger
capi
SF Senior Mod
SF Senior Mod


Joined: 21 Sep 2003
Posts: 16777097
Location: Portugal

Offline

PostPosted: Tue Jul 27, 2010 2:19 am    Post subject: Reply with quote

What rvdwesten said. Also...
zzddk wrote:
My guess was to use the handle_signal method [...]

The handle_signal... method?!?!?!
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Community Area

Log in | Register