Commit Graph

83 Commits

Author SHA1 Message Date
nichogenius
b5c31c97fc added a forgotten flag to the help
looks like i forgot to add the --no-color option to the help display.
2017-08-19 20:52:08 -06:00
nichogenius
b503b8124c Added Comments and Documentation
Added Comments and Documentation
2017-08-19 19:55:04 -06:00
nichogenius
015cc6f668 fixed -m checksum flag
fixed -m checksum flag
2017-08-19 17:55:19 -06:00
nichogenius
7a8a2c1c77 updated flags
updated flags

checksum can be -m for md5
comment can be -c for comment
2017-08-19 17:50:46 -06:00
nichogenius
dea08acd2e large 'scan' function broken up comment flag added
scan function has been broken up into a multiple functions which should make it more modular if future scan types are needed.
--comment, -a flag was added which prints the first comment to appear prior to the matched pattern in the pattern file.
2017-08-19 17:46:09 -06:00
nichogenius
ea2da42f8e Added comment lines for each regex
Added comment lines for each regex
This is to allow the -comment flag to provide either an accurate comment or no comment at all.
2017-08-19 17:24:04 -06:00
nichogenius
1f352dc4b4 added b64 pattern for 'require'
added b64 pattern for 'require'
2017-08-19 17:05:23 -06:00
nichogenius
3ff125a978 removed redundant pattern
'create_function' is redundant as 'function' is already present.
2017-08-19 17:02:18 -06:00
nichogenius
4161148d3c base64 pattern updates 2017-08-19 16:58:28 -06:00
nichogenius
dc60cea192 Bug Fixes, added time/checksum flags, organized
--Fixed a bug with the out function.  Previous updates of mine did not update all calls to the out function which I changed the parameters for.  Fixed this by replacing the out function with an 'error' function.
--Alphabetized function definitions and did some general tidying up
--Made all functions private except the constructor.
--Created parseArgs function to handle reading in options.
--Fixed a bug with 'extra-check' where htaccess and googleBot were being pushed to the pattern array each time a file was scanned. 
 This bug was created when I moved the pattern initialize code to the constructor.  Moved extra-check code with the rest of the initialize pattern calls.
--Added -no-color, -time, and -checksum flags.  I'd prefer if the output was only as spammy as the user requests.  Time should be helpful in tracing when the attack occurred and if files are related to the same hack.  Time and checksum do not display by default.  no-color flag makes it easier to dump to plain text files.
2017-08-19 12:57:49 -06:00
nichogenius
44aafb0972 Cleaned up pattern whitespace and comment handling
checking for comments and whitespace lines in pattern files should only be done once when the patterns are loaded.
Added this code to the loadPatterns() function and removed it from the 3 scan loops.
2017-08-18 07:31:33 -06:00
nichogenius
1909eb0781 Pattern Loading Moved To Constructor
It makes more sense to put the one time pattern load code into the constructor rather than the scan method.
2017-08-16 01:39:44 -06:00
nichogenius
575278613e Verbose Bug fix and pattern loading optimization
Verbose flag was not proceeding with the next scan due to !found being set.  Added a check to see if it is verbose when it decides to do the next scan.

Patterns should be loaded once and only once.  The files aren't large so not a problem with memory, however it might impact performance if we are loading the same 3 files ever time we scan a file.
2017-08-16 01:29:58 -06:00
nichogenius
b4e09e682a FilesMan Needs to be a regex
FilesMan Needs to be a regex
2017-08-16 00:55:15 -06:00
nichogenius
0fa5ac96f6 Removing fopen('/etc/passwd - Redundant
fopen('/etc/passwd dropped
sub-pattern /etc/passwd exists and is completely contained within fopen('/etc/passwd
2017-08-16 00:31:48 -06:00
nichogenius
0a1830cafb Raised Long PHP line Limit
Previous limit of 750 chars enclosed in php tags in a single line was too low... false positives were being triggered by a w3 total cache file because some guy decided to print one gigantic long message in a single line.

Raising to 1100
2017-08-16 00:26:16 -06:00
nichogenius
62e25eb5f8 Several Significant changes to scan.php
- Gave each flag option a short or long option; like i:ignore or d:directory or k:hide-ok
- Added a verbose option that instructs the scan to scan a file for ALL matches and not just stop at the first one.
- Restructured the output code to allow for the verbose flag, mainly a new function printPath and where the md5 hash is computed
- Modified the output to be cleaner, checksum is printed first as it is fix-width and to make it easier to paste into the whitelist file.
- Modified the output to be 'bash safe', ie when I accidentally paste my scan results into my terminal, the '#' should make sure everything is treated as a comment.  This is in contrast to possibly attempting to execute absolute paths to potentially malicious PHP scripts and the usage of the '>' which tells the shell to write to a file.  Also enclosed each path in {} for similar purposes.
- Printing the matched string/pattern in $color... might change later depending on  preference.
2017-08-16 00:11:54 -06:00
nichogenius
b2099f2424 Added New Malware Signatures/Fingerprints
IndoXploit
FaisaL Ahmed aka rEd X
'F'.'il'.'esMan'
FilesMan
2017-08-15 23:58:49 -06:00
nichogenius
3b8dff160b Added Experimental Patterns
Removed anyresults.net from the base64 pattern strings.

Added base64 patterns for $_POST $_GET $_REQUEST $_COOKIE extract and GLOBALS
2017-08-15 23:51:37 -06:00
nichogenius
b7942d6874 preg_match 's' flag changed to 'm'
the 's' flag tells preg_match to operate in multi-line mode.  the 'm' flag does the same, but allows line begin and ends to still be matched which is useful in some cases.
2017-08-15 12:04:59 -06:00
nichogenius
19589b8311 Added long single line PHP code pattern
One common tactic is to shove all of your PHP code into a single line, often contained within its own PHP tags, and drop it into any .php file that you want.  This pattern should detect if more than 750 characters are contained within PHP tags on a single line.
2017-08-15 12:03:19 -06:00
nichogenius
ab8a6c471a Added new flag options
Added a single short flag for every long flag and a single long flag for every short flag.
This now gives us 2 ways to set each flag.
Also updated the showhelp.
Dropped an unnecessary 'else' statement.
2017-08-15 09:14:31 -06:00
nichogenius
d7d85f13c7 Added encoded versions of '_' character.
Added encoded versions of '_' character.
2017-08-03 10:33:00 -06:00
nichogenius
4d9bcd171b Adding str_, function, echo and include in base64
str_ will match 13 separate php functions, many of which can be used for string/modifcation aka obfuscation
function added to catch function defining.
echo added as it is a  common php  keyword, though experimental... may cause a of false positives
include added as it is often used to link in other malware files.
2017-07-31 12:56:15 -06:00
nichogenius
32e2f68e92 Copied comments from php_functions.php
Copied comments from php_functions.php
2017-07-31 12:38:27 -06:00
nichogenius
62945f12d1 Renamed to match naming conventionsi
Renamed to match naming conventionsi
2017-07-31 12:35:01 -06:00
nichogenius
22f3da467b PHP Keywords in Base64, pattern file
This is a file containing a list of PHP keywords converted to base64.  It's designed to be used as a pattern file to identify common keywords used in obfuscated code.
2017-07-31 12:34:00 -06:00
nichogenius
9d60271b11 Added array_ and cslashes
Found a couple of cases where the php functions array_shift and addcslashes were used in base64 encoded malware.

Adding strings to catch any references to 'cslashes' which will catch both addcslashes and strip cslashes
Adding strings to catch any references to 'array_' which will catch about a dozen array modification functions.
2017-07-31 04:02:04 -06:00
nichogenius
b9b5de9e72 removed mail b64, added chr b64
removed mail b64, added chr b64

mail was generating too many false positives.
chr has only one pattern that is long enough to use with any sort of reliability, but it is one that we want to look out for anyway.
2017-07-28 06:57:23 -06:00
nichogenius
a18dabce83 this is not a bug... just fixing a bad bug fix
this is not a bug... just fixing a bad bug fix.
there is no off by 1 error after all.
2017-07-28 06:33:07 -06:00
nichogenius
9824951ad5 I was wrong... original code was correct.
I was wrong... original code was correct... there was no bug but the one in my head
2017-07-28 06:32:14 -06:00
nichogenius
4014f414dc This is how I generate base64 sample patterns.
Example usage:

I want to see if a giant block of base64 code contains any references to the string 'base64'. 
The naive approach is to convert the string to it's base64 equivalent, YmFzZTY0.

There are two problems with this approach.  The first is that the string will be different depending on the position of the first character 'Y' in the input string.  Possible offents are 0 bits, 2 bits or 4 bits.  The above example only calculates the 0 bit offset.  There should be 3 separate base64 strings to look for.

The second problem is that base64 strings use a 6 bit encoding, so the characters don't align the same as 8 bit encoding.  This leads to character bleeding at the beginning and ends of a string where the string will change depending on its immediate context.  This script calculates the maximum constant string length that should be present.  Unfortunately it requires trimming characters which can often lead to very short strings.
2017-07-28 05:15:39 -06:00
nichogenius
4f529f0683 Found a bug in my base64 converter
Found a bug in my base64 converter

My base64 conversion script is supposed to find the maximum length string that is guaranteed to be present if the input plain text string is somewhere in the original plain text code, however there was an off by 1 error which made some patterns 1 character longer than they should have been.   Short patterns (ie 4 chars) were prone to false positives because they really were 3 character patterns which is too short to be useful.  Long patterns were likely missing results.

Should be fixed now.
2017-07-28 04:51:18 -06:00
nichogenius
9bc41ee8b4 Added createfunction and gzinflate obfuscations
Added createfunction and gzinflate obfuscations.
also added gzinflate b64 patterns
2017-07-28 03:25:10 -06:00
nichogenius
d889aad1d6 obfuscat is too common, causes fp's
obfuscat is too common, causes fp's
2017-07-28 03:16:19 -06:00
nichogenius
13c6e7d81a removed datatran
removed datatran for false positives
2017-07-28 03:00:46 -06:00
nichogenius
296db40c8a Added http://www.fopo.com.ar/
http://www.fopo.com.ar/ is a free online php obfuscator that apparently leaves comments in the code which we should be looking for.
2017-07-28 02:38:08 -06:00
nichogenius
51389233fc Added obfuscat
obfuscat should catch things like obfuscated, obfuscator, obfuscation.
Some online obfuscator providers leave a signature comment in the code.
2017-07-28 02:35:25 -06:00
nichogenius
12249ae719 Typo fix
Typo fix
2017-07-27 23:18:26 -06:00
nichogenius
34867652d8 shortened base64_decode to just base64
shortened the base64 fingerprints of 'base64_decode' to just 'base64'. will also catch cases of base64_encode which isn't quite so bad but still worth finding.
2017-07-27 23:14:23 -06:00
nichogenius
92d891f212 added file_get_contents, fopen
dropped allow_url_fopen as fopen will catch those references on its own.
2017-07-27 23:11:18 -06:00
nichogenius
3f516f9e15 added create_function
interesting note from the php.net manual on create_function:
Caution
This function internally performs an eval() and as such has the same security issues as eval(). Additionally it has bad performance and memory usage characteristics.
2017-07-27 23:07:54 -06:00
nichogenius
20fa892b51 just adding some comments
just adding some comments
2017-07-27 22:59:11 -06:00
nichogenius
0e40b194e6 Uploaded an organized and commented version
This file just contains a list of internal php 7 functions (probably incomplete depending on extensions etc) and their 3 base64 fingerprints. It is designed to be used as either a pattern file to explore potential patterns that may be effective, or simply as a reference to translate between plain text php and the 3 different base64 versions.
2017-07-27 22:53:33 -06:00
nichogenius
eceff0545e ovh removed
ovh removed
2017-07-27 08:59:23 -06:00
nichogenius
1a5020d65d bad idea... lots of fps
bad idea... lots of fps
removing base_convert
2017-07-27 07:47:04 -06:00
nichogenius
954cfeb10a Adding base_convert as a test
base_convert seems like a rare enough function... trying it out to see if it generates many fp's.
2017-07-27 07:41:58 -06:00
nichogenius
26fd5d91e7 Removed (chr\(\d+\)\.){4,}
Too many false positives
2017-07-27 07:27:37 -06:00
nichogenius
317ff8b6b7 Added functions, dropped Spammer.
Spammers gives false positives.  added a couple more php functions in base64
2017-07-27 07:08:05 -06:00
nichogenius
c4cac57689 Removed some nasty false positive patterns
Removed some nasty false positive patterns
2017-07-27 05:57:28 -06:00