Skip to content

Instantly share code, notes, and snippets.

@adionditsak
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adionditsak/975764eba35273856be1 to your computer and use it in GitHub Desktop.
Save adionditsak/975764eba35273856be1 to your computer and use it in GitHub Desktop.
Check GHOST vulnerability one-liner with most reliable check script: curl -kL https://gist.githubusercontent.com/adionditsak/975764eba35273856be1/raw/2f9b31e39c22c03d6ef2152f8128165ef7c1aa27/check_ghost.sh | bash
#!/bin/bash
red='\033[0;35m'
NC='\033[0m'
echo "Downloading GHOST check script"
curl -kL https://gist.githubusercontent.com/adionditsak/975764eba35273856be1/raw/e5812798b8dffd139d3be8663a6bedf4eeeeb613/GHOST.c -o GHOST.c
echo "Compiling GHOST check script"
gcc GHOST.c -o GHOST
RESULT=$(./GHOST)
echo -e "${red}${RESULT}${NC}"
echo "Vacuuming..."
rm GHOST.c GHOST
echo "Done"
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define CANARY "in_the_coal_mine"
struct {
char buffer[1024];
char canary[sizeof(CANARY)];
} temp = { "buffer", CANARY };
int main(void) {
struct hostent resbuf;
struct hostent *result;
int herrno;
int retval;
/*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
char name[sizeof(temp.buffer)];
memset(name, '0', len);
name[len] = '\0';
retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
if (strcmp(temp.canary, CANARY) != 0) {
puts("vulnerable");
exit(EXIT_SUCCESS);
}
if (retval == ERANGE) {
puts("not vulnerable");
exit(EXIT_SUCCESS);
}
puts("should not happen");
exit(EXIT_FAILURE);
}
[root@host ~]# curl -kL https://gist.githubusercontent.com/adionditsak/975764eba35273856be1/raw/2f9b31e39c22c03d6ef2152f8128165ef7c1aa27/check_ghost.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
125 377 125 377 0 0 3485 0 --:--:-- --:--:-- --:--:-- 25133
Downloading GHOST check script
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 905 100 905 0 0 6749 0 --:--:-- --:--:-- --:--:-- 56562
Compiling GHOST check script
not vulnerable
Vacuuming...
Done
curl -kL https://gist.githubusercontent.com/adionditsak/975764eba35273856be1/raw/2f9b31e39c22c03d6ef2152f8128165ef7c1aa27/check_ghost.sh | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment