LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-08-2018, 04:22 PM   #1
syrius
LQ Newbie
 
Registered: Nov 2018
Posts: 3

Rep: Reputation: Disabled
PHP script that detects if auth is required or not on Apache Splunk


I am currently trying to do a PHP script that detects automatically if Apache Splunk authentication is required or not but I'm having a hard time since HTTP code 303 is always coming back, even if auth is required or not.

Here is the script so far;

Code:
<?php
/**
 * Apache Splunk script to verify if auth is required or not
 * Original Author: Damian HARt
 * Version : 1.0
 */
ini_set('memory_limit', '800M'); // Set ram limit
require('zebracurl.php');

if($argc === 3){
    $file = $argv[1];
    if(is_readable($file)){
        $handle = fopen($file, 'r');
        if ($handle){
            $i = 0;
            $curl = new Zebra_cURL();
            $line_id = 0;
            $total_lines = count_lines(__DIR__.DIRECTORY_SEPARATOR.$file);
            $url_to_check = array();
            $curl->threads = 100;
            $curl->option(array(CURLOPT_TIMEOUT => 20));
            echo 'Welcome in Apache Splunk detector'.PHP_EOL;
            echo '[!] Total lines to parse in '.$file.': '.$total_lines.PHP_EOL;
            echo '--------------------------------------------------------------------------------'.PHP_EOL;
            while (($uri = fgets($handle)) !== false){
                if (!empty($uri) ){
                    $url_to_check[] = trim($uri).':'.$argv[2].'/splunk/en-US/manager/search/apps/local';
                    if ($i === 99 || $line_id + 1 === $total_lines){
                        $curl->get($url_to_check, function($request){
                            if ($request->response[1] == CURLE_OK && $request->info['http_code'] === 200){
                                for ($_i = 0; $_i < count($request->headers['responses']); $_i++){
                                    $header_array = array_change_key_case($request->headers['responses'][$_i], CASE_LOWER);
                                    if (isset($header_array['Server'])){
                                        file_put_contents('results.txt', $request->info['original_url'].PHP_EOL,FILE_APPEND | LOCK_EX);
                                        echo '[+] '.$request->info['original_url'].PHP_EOL;
                                    }
                                }
                            }
                        });
                        $i = 0;
                        $url_to_check = array();
                    }
                }
                $i++;
                $line_id++;
            }
        } else {
            echo setColor('An error was occurred on file opening '.$config['input_file'], $with_color ? 'danger' : '').PHP_EOL;
            fclose($handle);
            unset($curl);
            die();
        }
        fclose($handle);
        unset($curl);
    }
}else { echo '[!] Usage: php splunk-detector.php LAN-IPs.txt 8000'; }

function count_lines($file){
    $total_lines = 0;
    if (file_exists($file)){
        $handle = fopen($file, "r");
        while (!feof($handle)){ if (fgets($handle) !== false) $total_lines += 1; }
        fclose($handle);
    } return $total_lines;
}
I am open to any solutions/suggestions as long as I can accomplish my goal.

Thanks

Last edited by syrius; 11-09-2018 at 03:54 PM.
 
Old 11-09-2018, 05:14 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 9,975
Blog Entries: 7

Rep: Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465Reputation: 2465
Quote:
Originally Posted by syrius View Post
I am currently trying to do a PHP script that detects automatically if Apache Splunk authentication is required or not but I'm having a hard time since HTTP code 303 is always coming back, even if auth is required or not.

Here is the bash script so far;
etc.

this is not a bash script; i think it's a PHP script.

we do not know what apache splunk authentication is and what the larger context here is (i doubt that posting one script is enough context).

learn to formulate your problem properly, incl. commands, code and configs, and you're halfway to a solution.
 
Old 11-09-2018, 02:10 PM   #3
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 2,024

Rep: Reputation: 629Reputation: 629Reputation: 629Reputation: 629Reputation: 629Reputation: 629
A 303 response from the server is a Redirect: Get Other Does that help you figure out what's happening?

As ondoho said, there's not near enough information in your OP. What have you already tried to debug your code?
 
Old 11-09-2018, 03:55 PM   #4
syrius
LQ Newbie
 
Registered: Nov 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
A 303 response from the server is a Redirect: Get Other Does that help you figure out what's happening?

As ondoho said, there's not near enough information in your OP. What have you already tried to debug your code?
So far, based on my research, we cannot detect it from HTTP code since all the time it returns an HTTP code 303. The only way I could detect if auth is required or not, is by some keyword in the source when auth is not required versus when auth is required.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache - mod auth external with php kptn3m0 Solaris / OpenSolaris 4 04-27-2011 04:30 PM
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 03:07 AM
Invoking a PHP script - sometimes the full path is required sneakyimp Linux - Newbie 4 05-26-2008 06:38 PM
Required packages for Apache/PHP/MySQL? Help with my web server. shadin Slackware 4 07-05-2006 09:57 PM
what is the best distro for web developers...mysql, php, and apache required sketchydave Linux - Distributions 4 11-24-2005 04:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration