Exam Information
Free practice questions with explanations
GIAC GPYC Practice Questions
Answer a question to see the correct answer and the explanation, or click Show answer. Newest questions first.
- Questions
- 12
- Answered
- 0
- Correct
- 0
- Score
- -
-
1 Question 1 Single choice Control Structures and Iteration
A penetration tester is writing a Python script to triage a list of open TCP ports returned by a scan. Ports 22 and 3389 must be reported as remote-access findings, ports 80 and 443 as web findings, and every other port must be logged as unclassified without stopping the loop. The list may contain ports that are already marked as closed by the scanner, which must be skipped entirely. The tester wants the most readable and correct structure. Which approach meets all requirements?
Correct Answer: AExplanationThe continue statement skips the remainder of the current iteration, which is exactly what closed ports need without ending the loop, while an if/elif/else chain ensures each open port falls into exactly one category and the else branch captures everything unclassified. Using break on a closed port would stop processing of all later ports, violating the requirement that the loop continue. A pass statement does nothing and would still fall through to classification of closed ports, and a separate if for unclassified ports can double-log. Folding web and unclassified together in one else loses the required distinction between the two categories.
-
2 Question 2 Single choice Creation of Executables
A red team operator must deliver a Python-based post-exploitation agent to a Windows 10 workstation in a client environment. The client requires that the delivered binary not open a visible console window when run by the user, and that the build pipeline be reproducible on a Linux build host. The operator considers packaging the script with PyInstaller. Which configuration best satisfies the requirements?
Correct Answer: BExplanationPyInstaller does not cross-compile: a Windows executable must be produced by a Windows build environment, and running PyInstaller inside Wine with a Windows Python interpreter is the usual way to achieve this from Linux while keeping the build reproducible. Combining --onefile with --noconsole produces a single windowed executable. Editing the spec file to disable the console flag is a valid mechanism in principle but does not resolve the cross-platform build requirement on its own. Renaming the file extension to .scr does not change how the binary is built and would not suppress the console. Using --windowed without --onefile satisfies the console requirement but produces a directory distribution, which the description of delivering a single binary rules out.
-
3 Question 3 Single choice Data Structures
A penetration tester intercepts a binary protocol message in which a 2-byte big-endian length field is followed by a payload encoded in Latin-1. The tester needs to recover the payload as text and also modify a single byte in place before replaying the message. Which Python approach is correct for both tasks?
Correct Answer: CExplanationBytes objects are immutable, so an in-place modification requires a bytearray, and Latin-1 decoding is what the protocol specifies for the payload. Decoding with UTF-8 can raise errors or produce different text for bytes above 0x7F, so the protocol's encoding must be respected. A str is immutable too, and tuples of characters cannot replace a byte. Assigning to an index of a bytes object raises TypeError. Decoding the whole buffer with ASCII fails on the length prefix and high-bit bytes, which is why the buffer should be sliced to the payload and decoded with the correct codec.
-
4 Question 4 Dropdown Database Interaction
A tester is auditing a web application's login feature against a local SQLite copy of the user table provided for testing. The script must use parameterized queries so that the test payloads are passed as data rather than concatenated into the SQL string. Complete the code by selecting the correct value for each blank.
Choose the correct value for each blank.
import sqlite3
conn = sqlite3.connect('test_users.db')
cur = conn.cursor()
cur.('SELECT id FROM users WHERE name = ? AND pwd = ?', (user, pwd))
row = cur.()
conn.()Correct Answer:import sqlite3
conn = sqlite3.connect('test_users.db')
cur = conn.cursor()
cur.execute('SELECT id FROM users WHERE name = ? AND pwd = ?', (user, pwd))
row = cur.fetchone()
conn.close()ExplanationThe sqlite3 cursor method execute accepts a SQL string and a sequence of parameters bound to the question-mark placeholders, which keeps the payload as data. The cursor method fetchone returns the next row or None, which suits a single login lookup. The connection method close releases the database handle at the end of the test. executemany expects a sequence of parameter sets and would be incorrect for a single lookup, run and query are not sqlite3 methods, fetchone is the only valid row-retrieval method, readone and getrow do not exist, commit is unnecessary for a read-only query and rollback would discard pending work, and terminate is not a connection method.
-
5 Question 5 Single choice Exception Handling
A tester's script repeatedly connects to a list of target hosts to check whether a service responds. Some hosts refuse connections, some time out, and some fail DNS resolution with socket.gaierror. The script must record each failure, continue scanning remaining hosts, and never swallow unexpected programming errors such as a NameError inside the loop. Which exception handling structure best meets the requirements?
Correct Answer: BExplanationCatching the specific exception types ConnectionRefusedError, socket.timeout, and socket.gaierror records the expected network failures per host while letting genuine programming errors such as NameError propagate, which is exactly what the requirement describes. A bare except would hide programming errors and also catch KeyboardInterrupt. Wrapping the whole loop with except Exception would stop the scan at the first failure, contradicting the requirement to continue. Catching BaseException is broader still and would also intercept interpreter-exit signals, making it an unsafe choice even with a finally block.
-
6 Question 6 Multiple choice Functions, Classes, and Objects
A tester is building a reusable Python module for a team that manages many scanner plugins. Each plugin must share a common run() interface and identical logging behaviour, and the team wants to avoid duplicating the logging code while keeping plugin-specific state isolated between instances. Which TWO design choices best satisfy these requirements? (Choose two.)
Correct Answer: A, BExplanationA base class that declares run() and raises NotImplementedError gives all plugins a common interface, and inheriting the shared logging method removes duplication. Setting per-object state in __init__ as instance attributes keeps each plugin's data isolated. A mutable class attribute is shared across all instances, which breaks isolation. A module-level logger reassigned by each plugin would let plugins overwrite each other's configuration. Copying the logging code into every plugin directly violates the requirement to avoid duplication.
-
7 Question 7 Drag and drop Network Interfaces
A tester is writing a Python TCP client to probe an internal service that sometimes accepts connections slowly and is protected by a host firewall that silently drops packets. The client must not hang indefinitely, must send a banner-grab request, and must read the response in a loop until the server closes the connection. Match each requirement to the socket feature that satisfies it.
Drag each item onto its matching target. On a phone: tap an item, then tap a target.
Establish the TCP connection to the remote host and portPrevent the client from blocking forever when the firewall drops packetsRead the response until the server closes the connectionrecv in a loop until an empty bytes resultsetsockopt with SO_REUSEADDRconnect with an address tuplesettimeout on the socketbind to a local ephemeral portCorrect Answer:- Prevent the client from blocking forever when the firewall drops packets → settimeout on the socket
- Establish the TCP connection to the remote host and port → connect with an address tuple
- Read the response until the server closes the connection → recv in a loop until an empty bytes result
ExplanationA socket timeout causes blocking operations such as connect and recv to raise socket.timeout after the given interval, which handles silently dropped packets. The connect method with an address tuple initiates the TCP handshake to the target. A recv loop that stops when it returns an empty bytes object detects an orderly close by the peer. SO_REUSEADDR affects rebinding of local addresses and does not govern timeouts or remote connections, and binding to an ephemeral port is unnecessary for an outbound client that the operating system assigns automatically.
-
8 Question 8 Single choice Packet Analysis with Python
A tester has captured a PCAP of a suspected DNS tunnel and needs to find hosts sending unusually long DNS query names, which often indicate data exfiltration. The capture has about 2 million packets, and the analyst must avoid loading the whole capture into memory. Using Scapy, which approach is most appropriate?
Correct Answer: AExplanationScapy's PcapReader yields packets one at a time from the file, so the 2-million-packet capture never resides fully in memory, and checking the DNS query name length per packet directly identifies the suspicious hosts. Loading everything with rdpcap is exactly what the memory constraint forbids. Sniff operates on a live interface rather than a saved capture, so it does not fit an offline analysis. Rewriting the file with wrpcap and then reloading it with rdpcap still loads everything into memory and adds no benefit.
-
9 Question 9 Single choice Regular Expressions
A tester must extract hostnames from a web application's exported log lines, where each line has the form 'GET https://api.example.com:8443/v1/users HTTP/1.1' and the host may be followed by an optional port. The regex must capture only the hostname, not the scheme, port, or path, and must not match an IP address with a trailing dot. Which pattern best satisfies these requirements?
Correct Answer: DExplanationThe pattern https?:// anchors on the scheme, the capture group takes the hostname characters, and the optional non-capturing group (?::\d+)? absorbs the port without including it in the capture, while the trailing slash anchors the end of the host before the path. Using a greedy wildcard in B would capture far too much including the port and path. C requires a port, so it fails on URLs without one, which the requirement allows. D hard-codes a .com suffix and would miss other top-level domains and the scheme-anchored context entirely.
-
10 Question 10 Dropdown Website Interaction
A tester is automating a login flow against a staging web application using the requests library. The session must persist the authentication cookie across subsequent requests, and the tester must verify the cookie that the server set during login. Complete the code by selecting the correct value for each blank.
Choose the correct value for each blank.
import requests
s = requests.()
resp = s.('https://staging.example.test/login', data=creds)
print(s..get_dict())Correct Answer:import requests
s = requests.Session()
resp = s.post('https://staging.example.test/login', data=creds)
print(s.cookies.get_dict())ExplanationA requests.Session object stores cookies set by responses and sends them automatically on later requests made through the same session, which provides the persistence needed. The login form submission is a POST with form data, so the session's post method is correct. The session.cookies attribute is a cookie jar, and its get_dict method returns the cookies as a plain dictionary for verification. Connection and Client are not requests classes, put and patch are the wrong HTTP verb for a form login, fetch is a JavaScript API rather than a requests method, headers holds response headers rather than cookies, auth configures credentials rather than storing cookies, and cache is not a session attribute.
-
11 Question 11 Single choice Website Interaction
An external penetration test requires that a Python crawler authenticate to a web portal that uses CSRF tokens embedded in each form. The crawler must submit a login form that includes a hidden token value that changes on every page load. The tester wants a reliable, repeatable method. What is the correct sequence of actions within a single session?
Correct Answer: DExplanationThe token changes on each page load, so the crawler must first fetch the login page within a persistent session so the server associates the token with that session, then extract the hidden value and submit it with the credentials through the same session. A token captured earlier is stale and will be rejected. Creating a fresh session for each request discards the server-side association that validates the token. The requests library does not add hidden form fields on its own, so omitting the token causes the login to fail.
-
12 Question 12 Single choice Python Basics
A tester writes a script that reads a customer-supplied wordlist file, which is encoded in UTF-8 and may contain a byte order mark. The script must read lines reliably, skip blank lines, and handle a missing file without crashing with an unhandled traceback. Which code approach best meets these requirements?
Correct Answer: AExplanationThe utf-8-sig codec strips a leading byte order mark that plain utf-8 would leave in the first line, and a with block guarantees the file closes. Stripping each line before testing for emptiness skips blank lines correctly, and catching FileNotFoundError gives a controlled message. Reading with the default encoding can misdecode UTF-8 content on some systems and ignores the missing-file requirement. Latin-1 decoding will silently misread multi-byte UTF-8 characters, and a bare except hides real errors. Checking existence first is racy and plain utf-8 keeps the byte order mark, while not stripping leaves blank lines with whitespace in the output.
These are 12 of the 75 questions in the full GPYC pack.
Get All 75 QuestionsGet all 75 questions & answers
Full access options for GIAC GPYC
Self-study
PDF Version
- 75 actual exam questions
- Compatible with all devices
- Printable PDF format
- No download limits
- 90 days free updates
- 24/7 customer support
Best value
Bundle Pack
- Discounted PDF + online access
- 75 actual exam questions
- Both PDF and online practice test
- Free 90 days updates
- No download or practice limits
- 24/7 customer support
Exam simulation
Online Practice Test
- 75 actual exam questions
- Actual exam environment
- 90 days free updates
- Browser-based software
- 24/7 customer support
100% Money Back Guarantee
Your success comes first
At DumpsProvider, we give you a 100% money back guarantee on all of our exam dumps. For us, your success is the #1 priority and we are more than confident that our exam material will help you pass the GPYC Exam (GIAC Python Coder) on your very first attempt.
In a rare case, if you fail your exam, we will refund your amount without asking a single question.