Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:19:28+00:00 2026-06-17T20:19:28+00:00

I just wrote a ping script in C for CGI. It is working as

  • 0

I just wrote a ping script in C for CGI.

It is working as intended but I am pretty sure that it is not secure because I take the user input for granted.
I do not know if there is a way to stitch a command together so that it is still recognised?

Does somebody know how to exploit my script and how I should fix it?

ping script source

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
  printf("Content-Type: text/plain;charset=us-ascii\n\n");

  FILE* in = NULL;

  char buffer[100][100] = {};
  char server[100] = {};
  char concat_str[100] = {};

  char* ping = "ping ";
  char* option = " -c 4";

  int print_counter = 0;
  int read_counter = 0;

  char* query;
  query = getenv("QUERY_STRING");
  if(query == NULL)
    printf("ERROR\n");
  else
    sscanf(query,"server=%s", server);

  strcat(concat_str, ping);
  strcat(concat_str, server);
  strcat(concat_str, option);

  in = popen(concat_str, "r");
  if(in == NULL)
  {
    printf("ERROR\n");
    exit(1);
  }

  while(fgets(buffer[read_counter], 99, in) != NULL)
  {
    read_counter++;
  }

  pclose(in);

  if(read_counter != 9)
  {
    printf("ERROR\n");
    exit(1);
  }

  while(print_counter < (read_counter + 1))
  {
    printf("%s", buffer[print_counter]);
    print_counter++;
  }

  return 0;
}

html source

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="http://xx.xx.xx.xx/ping.cgi">
<div><label>Server<input name="server" size="40"></label></div>
<div><input type="submit" value="start test"></div>
</form>

</body>
</html>

On a related note, is there an easy way to post the source code directly here without manually intending it 4 spaces?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:19:29+00:00Added an answer on June 17, 2026 at 8:19 pm

    Definitely not secure. The popen() function passes its argument to a subshell, so shell metacharacters like ; could be passed in through the query string to execute an arbitrary command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just wrote a Magento module, but it's not being loaded and I'd like
Hey I just wrote a Hello World code for ASP. But it is not
I copied this script from here but I'm not sure how to modify it
I just wrote some code that works very well. But I feel that it
I just wrote an XSLT that did not work at first. I had to
I just wrote a very simple perl tk script to read a huge text
I just wrote a PHP login script, and what I'm trying to accomplish is
I just wrote a stored function to calculate the working days between two dates.
I just wrote a simple DirectShow Filter (which inherits from CTransformFilter). But I want
I just wrote a simple extension that has permission to *.google.com and changes some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.