Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Description: ghost_check.sh
Submitted on January 28, 2015 at 04:13 PM

Section 1 (Bash)

#!/usr/bin/env bash

SCRIPT_TAG="GHOST_CHECK_`date +%Y%m%d`.0"

TMP="/var/tmp"

if [ ! -d ${TMP} ]; then
	mkdir -pv ${TMP}
fi

GHOST_SRC="${TMP}/ghost.c"
GHOST_BIN="${TMP}/ghost"

cat > ${GHOST_SRC} << EOF
#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);
}
EOF

gcc ${GHOST_SRC} -o ${GHOST_BIN}
if [ $? -ne 0 ]; then
	echo "! ERROR: GCC failed to compile ghost"
	echo "${SCRIPT_TAG}_ERR_01"
	exit 1
fi
cd ${TMP}
GHOST_BIN_NAME=`basename ${GHOST_BIN}`
GHOST_OUT=`./${GHOST_BIN_NAME}`
echo "+ Ghost output is ${GHOST_OUT}"
if [ "${GHOST_OUT}" == 'vulnerable' ]; then
	echo "GHOST_FOUND_VULN"
	echo "+ getting list of information"
	rpm -qa | grep -i glibc
	echo "${SCRIPT_TAG}_ISVULN"
	exit 0
else
	echo "GHOST_NOT_FOUND_VULN"
	echo "${SCRIPT_TAG}_NOTVULN"
	exit 0
fi