Defensive Programming
Defensive Programming
Q.1 (a) Describe the defensive programming importance as a cybersecurity expert. If web
application code is vulnerable, then what possible threats may occur?
Defensive programming is a practice to write code that functions correctly even under unforeseen
circumstances or malicious inputs. It enhances:
Q.1 (b) Differentiate between vulnerability assessment and penetration testing. Discuss the steps
of the Penetration Testing Method with an appropriate diagram.
Difference:
Q.2 (a) Discover improper input validation and likelihood of exploit in the below code.
Code Example:
chargeUser(total);
The code does not validate the quantity input, allowing invalid or malicious values.
Likelihood of Exploits:
Q.2 (b) What is the full form of PASTA? Summarize the threat modeling process of PASTA with the
desired property of each threat.
Full Form:
Process:
Q.3 (a) Discover and print previously connected wireless networks along with their MAC addresses
using Python script.
import subprocess
def get_wifi_profiles():
get_wifi_profiles()
Q.3 (b) Build a Python script to establish communication between client and server using the
socket module.
Server Script:
import socket
server.bind(("127.0.0.1", 8080))
server.listen(1)
print("Server listening...")
message = conn.recv(1024).decode()
conn.send("Acknowledged".encode())
conn.close()
Client Script:
import socket
client.connect(("127.0.0.1", 8080))
client.send("Hello Server!".encode())
response = client.recv(1024).decode()
client.close()
Q.4 (a) What is SSH? Discover the use of methods of pexpect Python package which are used for
SSH connection.
pexpect Methods:
import pexpect
ssh.expect('password:')
ssh.sendline('your_password')
ssh.expect('$')
ssh.sendline('ls')
ssh.expect('$')
print(ssh.before.decode())
Q.5 (a) Who is the developer of the Metasploit Project? Explain how the Pentagon’s dilemma was
solved using TTL fields?
Developer:
TTL (Time-To-Live): A field in an IP packet that limits its lifetime in the network.
Q.5 (b) Write a Python script to detect a target IP’s physical location with latitude and longitude
using the pyGeoIP module.
import pygeoip
def get_geolocation(ip_address):
record = gi.record_by_addr(ip_address)
if record:
else:
# Example Usage
Q.5 (a) Criticize the operation Aurora and how the obvious was missed.
Critique:
1. Lack of Patch Management: Companies failed to apply timely updates for known
vulnerabilities.
2. Insufficient Monitoring: Intrusions were not detected early due to inadequate logging.
3. Weak Endpoint Security: Lack of advanced endpoint protection allowed malware to spread.
def sniff_ftp_credentials(packet):
if packet.haslayer(TCP) and packet.haslayer(Raw):
payload = packet[Raw].load.decode(errors="ignore")
print(f"Captured: {payload}")
# Example Usage
Q.5 (b) Build a Python script for Windows Memory Forensics - Memory Capture and Analysis.
import os
def capture_memory():
dump_file = "memory_dump.dmp"
def analyze_memory():
capture_memory()
analyze_memory()
Here are the answers to the provided exam questions: 28 Feb 2023
Penetration Testing:
1. Planning and Reconnaissance: Define the scope and gather information (e.g., domains, IPs).
2. Scanning: Identify live hosts and vulnerabilities using tools like Nmap.
Q.1 (b) What software do you need to install for practice penetration testing? Explain each.
1. Kali Linux: A Linux-based OS with tools like Metasploit, Wireshark, and Nmap.
3. OWASP ZAP: Automated tool for finding security issues in web apps.
Q.2 (a) What is Secure Code Review? List out Secure Code Review checklist.
Checklist:
Q.2 (b) What is threat modeling? Explain key steps of threat modeling process.
Threat Modeling:
Key Steps:
HTML5:
The latest version of the HTML standard for structuring web content.
Differences:
1. Multimedia Support: HTML5 includes support for <audio> and <video> tags.
3. New Elements: Tags like <article>, <section>, and <canvas> for semantic structure.
Socket:
Types:
import smtplib
def send_spoofed_email():
smtp_server = "smtp.example.com"
sender = "[email protected]"
recipient = "[email protected]"
send_spoofed_email()
Q.4 (b) Write a Python code to build Port Scanner.
import socket
sock.settimeout(1)
if result == 0:
sock.close()
# Example Usage
Registry Hive:
A registry hive is a logical group of keys, subkeys, and values in the Windows Registry, which stores
configuration data for the OS and applications.
Common Hives:
reader = PdfReader("example.pdf")
metadata = reader.metadata
print(metadata)
Firesheep was a tool that exploited a vulnerability in web applications to hijack user sessions. This
allowed attackers to steal cookies and gain unauthorized access to user accounts on various
websites, including social media platforms and online banking services.
1. Keep Software Updated: Ensure that your web browser and operating system are up-to-date
with the latest security patches.
2. Use HTTPS: Whenever possible, use websites that use HTTPS, as it encrypts communication
between your browser and the server, making it more difficult for attackers to intercept data.
3. Be Cautious on Public Wi-Fi: Avoid accessing sensitive accounts on public Wi-Fi networks, as
they are less secure.
4. Use a VPN: A VPN encrypts your internet traffic, providing an additional layer of protection.
5. Install Security Extensions: Browser extensions like HTTPS Everywhere and NoScript can help
protect your privacy and security.
6. Be Aware of Phishing Attacks: Be cautious of suspicious emails and links that may lead to
malicious websites.
Here are the answers to the provided exam questions: 29 Jan 2024
Q1 (a)
List software vulnerabilities along with appropriate defensive programming solutions. If an android
application code is vulnerable, then which possible threats may occur?
o Cross-Site Scripting (XSS): Validate and sanitize all user inputs and use content
security policies.
o Buffer Overflow: Employ bounds checking and avoid unsafe functions like strcpy().
o Insecure Data Storage: Encrypt sensitive data with strong algorithms (e.g., AES-256).
Q1 (b)
Discuss the steps of the Penetration Testing Method with a suitable diagram.
1. Steps:
2. Diagram:
Q2 (a)
Discover the possible attacks and likelihood of exploit in the below code.
Vulnerabilities:
o SQL Injection: Directly concatenating user input into the query exposes the system
to SQL injection.
Exploitation Example: If username = "admin" OR 1=1 --" and password is left empty, the
query becomes:
SELECT * FROM user_system_data WHERE user_name = 'admin' OR 1=1 --' AND password = ''
Q2 (b)
Differentiate between STRIDE vs. PASTA. Summarize the threat modeling process of PASTA.
1. Differences:
o Analyze threats.
o Exploit vulnerabilities.
o Analyze risks.
o Report findings.
Q3 (a)
Discover and print previously connected wireless networks along with their MAC address using
Python script.
import subprocess
def get_networks():
print(f"Network: {wifi}")
else:
get_networks()
Q3 (b)
Utilize the socket module and build a Python script to establish communication between client and
server.
1. Server Script:
2. import socket
3.
5. server_socket.bind(("127.0.0.1", 8080))
6. server_socket.listen(1)
8.
11.
15. break
18.
19. conn.close()
22.
25.
28. client_socket.send(message.encode())
30. break
32.
33. client_socket.close()