Username: 
Password: 
Restrict session to IP 
Questions  |  score: 4  |  4.29 5.75 6.62 |  Solved By 601 People  |  77831 views  |  since Mar 21, 2012 - 12:42:41

Choose your Path (Linux, Exploit, Warchall)

Choose your Path
This is the level10 mini challenge found in /home/level/10/ on the warchall box.
You can view the source here.

Proudly presented by Mart and the warchall staff.
GeSHi`ed C code for choose_your_path.c
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
39
4041
42
43
44
4546
47
48
49
5051
52
53
54
5556
57
58
59
6061
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h> 
#define BUFSIZE 256
 
int main(int argc, char *argv[])
{  FILE *fp;
  char buf[BUFSIZE];
  char *filename;
  int lines, chars, cpl;
   setregid(1011,1011); // set real and effective GID to level10
 
  if (argc != 2)
  {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);    exit(EXIT_FAILURE);
  }
  
  filename= argv[1];
  printf("Counting %s ... \n", filename); 
  if (snprintf(buf, BUFSIZE, "/usr/bin/wc -l %s", filename)>=BUFSIZE)
  {
    fprintf(stderr, "Filename %s is too long!\n", filename);
    exit(EXIT_FAILURE);  }
 
  fp= popen(buf, "r");
  if (!fp)
  {    fprintf(stderr, "Command execution failed! Sorry!\n");
    exit(EXIT_FAILURE);
  }
  if (1!=fscanf(fp, "%d", &lines))
  {    fprintf(stderr, "Cannot scan! Sorry!\n");
  }
  pclose(fp);
 
  snprintf(buf, BUFSIZE, "/usr/bin/wc -c %s", filename);  fp= popen(buf, "r");
  if (!fp)
  {
    fprintf(stderr, "Command execution failed! Bummer!\n");
    exit(EXIT_FAILURE);  }
  if (1!=fscanf(fp, "%d", &chars))
  {
    fprintf(stderr, "Cannot scan! Sorry!\n");
  }  pclose(fp);
 
  cpl= chars/lines;
 
  printf("Chars per line is %d.\n", cpl); 
  return EXIT_SUCCESS;
}
 
 
Your solution for Choose your Path
Answer
© 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 and 2024 by Mart and gizmore

Say *NO* to advertisements!