CSE 453 Problem Set 06: Exercises 05.03: C# and SQL
CSE 453 Problem Set 06: Exercises 05.03: C# and SQL
connection.Open();
command.ExecuteNonQuery();
connection.Close();
<?php
if (isset($_GET["IPAddress"]))
{
exec("/usr/bin/ping " . $_GET["IPAddress"]);
}
?>
Exercises 05.05: PHP and NS Lookup
For the following PHP code, answer the following questions:
● What is the code meant to do?
The code is meant to obtain user input via form, then assign it to a variable ($host), then append it to and execute a system execution.
<system> executes an external program and displays the output [1].
[1] https://www.phptutorial.info/?system
<?php
$host = 'byui.edu';
if (isset( $_GET['hostName'] ) )
$host = $_GET['hostName'];
system("/usr/bin/nslookup " . $host);
?>
<form method="get">
<select name="hostName">
<option value="server1.com">one</option>
<option value="server2.com">two</option>
</select>
<input type="submit"/>
</form>
Exercises 05.06: PHP and SQL
For the following PHP code, answer the following questions:
● What is the code meant to do?
The code will take the value of the $size variable and append it to the SELECT statement, then it will connect to the database, execute the
statement, and set the $result variable with the result. The $query variable is selecting a variable with a specified size. it is then taking the
specified string and sending it to the server with the command odbc_exec which takes in a resource and a string as parameters.
<?php
$query = "SELECT idProduct, size FROM products" .
"WHERE size = '$size'";
$result = odbc_exec($connection_id, $query);
?>
Exercises 05.07: PHP and SQL
For the following PHP code, answer the following questions:
● What is the code meant to do?
The code is meant to obtain a command line argument $argv[0] and save it into $value. The value of $value is then used in a SQL statement.
The SQL statement will select the id and name records from the products table, but only 100 records, beginning from a given place. That given
place is determined by the user’s input through the $argv[0] variable. After a connection has been established with the database, the query is
executed and the results are stored in the variable $result.
<?php
$value = $argv[0];
$query = "SELECT id, name " .
"FROM products " .
"ORDER BY name " .
"LIMIT 100 OFFSET $value;";
$result = odbc_exec($connection_id, $query);
?>
Exercises 05.08: Perl and NS Lookup
For the following PHP code, answer the following questions:
● What is the code meant to do?
The code is meant to allow the user to input a filename and find the list of hosts via <nslookup> command. Then, if a file name is provided, the
program will open the file, then print the user input back to the user, then a new line break.
“Because Runtime.exec() receives unsanitized data originating from the environment, this code is susceptible to a command injection attack”
[3].
vulnerabilities:
“1. A mechanism must exist to send text to the operating system command interpreter.
2. The text must be accessible through user input” (p. 111) [2].
[2] Helfrich
[3] https://wiki.sei.cmu.edu/confluence/display/java/IDS07-J.+Sanitize+untrusted+data+passed+to+the+Runtime.exec%28%29+method