25 Years of Programming Community Forum
Blog  Sitemap  Services
May 24, 2013, 06:08:01 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Admin gets an email whenever a new message is posted or a new member joins.
 
   Home   Help Search Login Register  
This is a link to the Chat Room (for Firefox+ChatZilla) when you are logged in.
View help topic about using Live Chat
Pages: « 1 2 3 4 5 6 7 8 9 10
 91 
 on: September 21, 2011, 11:03:03 AM 
Started by randyg - Last post by randyg
Hi I am trying to just email the results, do you know the proper syntax to include the results, into variable name $msg?
no matter what I try I keep getting a blank message in the email.

// I think this is the FUNCTION, I need to get the info from
FindAndProcessFiles($StartPath$FileMatchRegexes$FullpathExcludeRegexes'FindMaliciousCodeSnippets');

/*********************** SEND THE RESULTS **********************/
$subject "Report, ".$datestamp;
if (
$email=="1"mail($email_address$subject$msg);
if (
$email=="1") echo "<br>Email Sent";
/*********************** SEND THE RESULTS **********************/

Thanks
Randy

 92 
 on: September 17, 2011, 01:44:44 AM 
Started by SteveW - Last post by SteveW
I've created this thread for bug reports, feature suggestions, other feedback, or questions about the "lookforbadguys.php" script at "PHP script to find malicious code on a hacked server".

You can start a new message thread, if you prefer.

The idea for a support thread was inspired by a helpful question that has already been asked by someone in a separate thread:

Exclude a folder, bad guy php script  
It discusses the use of regular expressions to exclude files by filename, partial path+filename, or full and unambiguous path+filename.

The brief "notes about regular expressions" in this post might be helpful if you are very new to the use of regular expressions.

Because the lookforbadguys script achieves much of its flexibility through the use of regular expressions, you might find the following resources helpful:

Regex Tutorials

Try starting here
http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax

Also this popular page for another approach to the basics
http://gnosis.cx/publish/programming/regular_expressions.html

These next two resources are the regex tutorials for Perl. Although the Perl-specific code doesn't apply to PHP, the regex examples and walkthroughs are relevant and readable, and nearly the same as you use in PHP:

Quick tutorial: http://perldoc.perl.org/perlrequick.html
Longer tutorial: http://perldoc.perl.org/perlretut.html

Regex Reference Manuals

The text file http://www.pcre.org/pcre.txt (their home page is http://www.pcre.org) is the definitive and truly excellent reference to Perl Compatible Regular Expressions (it is the manpage for them). Skip the top half of the file and go to the section called PCREPATTERN. Although not a tutorial, it has lots of instructive examples.

This is the PCRE reference at php.net. It's rather formal and easiest to understand if you already know the material: http://us.php.net/manual/en/reference.pcre.pattern.syntax.php

 93 
 on: September 16, 2011, 11:47:57 PM 
Started by randyg - Last post by randyg
Thanks, you just explained something so clear that I always had a
hard time understanding before. this script is really powerful.

Thanks
Randy

 94 
 on: September 16, 2011, 09:56:42 PM 
Started by randyg - Last post by SteveW
I defined the $FullpathExcludeRegexes array 3 times (each occurrence overrides the previous) to make it clear that you can use a different list of exclusions for each search, but don't have to.

The technically correct way to define your own list is to define it 3 times in the 3 places shown. Basically, that means defining it once and then copying the code to the 2 other places.

However, if you want to use the same exclusion list for all the searches, you can also just define your list in the first instance, and then comment out or delete the 2 later instances where $FullpathExcludeRegexes is redefined.

Or, if you're really only interested in the results of the malicious snippets search (the last of the 3), you can just define your exclusion list in the array that precedes that search. Your definition there will override the previous definitions, "just in time" for doing the malicious snippets search.

Of course, you can also keep a master copy of the script, and then use a copy of it each time you run it. In the copy, you can delete all the code for the first two searches if you don't need to do them.

Excluding folders

Each regex entry in the exclusion list is matched against the full path of each file. For example, here is a fullpath:

/home/userid/public_html/25years/blog/2010/20100315.htm

To exclude this one file by name only, the regex could be

'#20100315\.htm$#'

The $ at the end means that the .htm must be the very end of the string. There must be nothing more after it. Without the $ to mark the end, that regex would also match and exclude the (unlikely) filename /blog/20100315.htm/somefile.php

If there are other folders that might have a file with that name, you could make the regex more specific with any of these, depending on how specific you need to be:

'#/2010/20100315\.htm$#'
'#/blog/2010/20100315\.htm$#'
'#^/home/userid/public_html/25years/blog/2010/20100315\.htm$#'

The third one has a ^ which marks the beginning of the string just like $ marks the end. In this case, the file will match the regex only if its entire path+filename exactly matches that whole string. That is the safest way to do a match.
 
The same principle applies to matching directories. To exclude the /blog/ directory, you could use this

'#/blog/#'

But if you have more than one /blog/ directory (in various other paths), you might have to be more specific about which /blog/ directory to exclude, with this regex

'#public_html/25years/blog/#'

or even this

'#^/home/userid/public_html/25years/blog/#'

Note that it has a starting ^ anchor, but in the case of a directory, it must not have an ending $ anchor because the string that this regex is being matched against will certainly have a filename after the ending "/".


In the array definition, all entries except the last one must end with a comma because it is a list. So here is an example with some of the lines from above:
 
$FullpathExcludeRegexes = array
(
	
'#lookforbadguys\.php$#i',
	
// but this matches any lookforbadguys.php file in any folder
	
'#20100315\.htm$#',
	
	
	
// any file with this name, in any folder
	
'#^/home/userid/public_html/25years/blog/#'
);

To completely avoid any possibility of ambiguity, you can make it a habit to always use full paths:

$FullpathExcludeRegexes = array
(
	
'#^/home/userid/public_html/lookforbadguys\.php$#i',
	
'#^/home/userid/public_html/25years/blog/2010/20100315\.htm$#',
	
'#^/home/userid/public_html/25years/blog/#'
);

As an advanced example, the regexes can do more complex things. This excludes .htm and .html and .php  and .txt files (and also .HTM .HTML .PHP .TXT because the "i" at the end means case-insensitive) in the /blog/ folder itself, but entries in its subfolders such as /blog/subfolder/ are not excluded:

$FullpathExcludeRegexes = array
(
	
'#^/home/userid/public_html/25years/blog/[^/]+\.(html?|php|txt)$#i'
);

 95 
 on: September 16, 2011, 03:59:27 PM 
Started by randyg - Last post by randyg
Thanks for the suggestion. The latest version now includes the feature to exclude files/folders.

Thanks, can you please show me how to exclude a directory with the new version?
do I need to enter a full path like "/home/.../directory/"

for individual file excluding do I enter the file to exclude in three places, with this new version
where I see '#lookforbadguys\.php#' like '#anotherfile\.php#'

thanks for the new feature
Randy

 96 
 on: September 16, 2011, 03:47:46 AM 
Started by randyg - Last post by SteveW
Thanks for the suggestion. The latest version now includes the feature to exclude files/folders.

 97 
 on: August 16, 2011, 01:25:59 PM 
Started by NineAllexis - Last post by SteveW
Only a lawyer could give you answers you could rely on, and I am not a lawyer. I, and other people online, can only give you their opinions based on what they've seen. 

Jailed: No way, not unless you *intentionally* put code in the site so it could be hacked or so you could hack it yourself later.

Sued: I think that's very uncommon, but it's not impossible. The other person could claim that the code was not up to an acceptable standard.  However, I'm not aware of there being any formal standards of acceptability that they could refer to in making that claim, unless you had a contract with them that defined a standard of acceptability. 

If you used a CMS like WordPress or Joomla, it would be the responsibility of the site's maintainer to keep the software upgraded to its latest version. Your work is not necessarily the reason that the site got hacked. It could have been because there was a security hole in the CMS. In that case, even the authors of the CMS could be considered at fault.

Or the site could have been hacked because they used weak passwords, or because one of their administrators got a virus on their PC that stole their FTP password, or for a variety of other reasons. Exactly how it happened would be very important to know. If someone wanted to sue you, they'd have to prove that it was the result of your work and not from some other cause.


My forum doesn't have very many members. You might get a wider variety of responses, maybe some replies from lawyers (even if they don't admit it), if you ask your question in a large forum like WebmasterWorld http://www.webmasterworld.com/webmaster_business_issues/ .

 98 
 on: August 15, 2011, 07:12:45 AM 
Started by NineAllexis - Last post by NineAllexis
Hi everyone.

I made a website with a CMS during my previous employment. Last year actually.
It was recently got hacked.

I was wondering if anyone here know that I could be held responsible, be sued or jailed for being the developer.
Thanks.

 99 
 on: August 11, 2011, 12:12:46 AM 
Started by randyg - Last post by randyg
Thanks, I know a little about php mainly cut and paste, I will try to exclude a directory
with the way you gave, this would be a really useful future update.

Thanks again

 100 
 on: August 11, 2011, 12:01:00 AM 
Started by randyg - Last post by SteveW
In find_files(), this code excludes certain directories. The tests could be rearranged and then modified to exclude others:

if(($entry !== '.') && ($entry !== '..') && is_dir($fullname))
	
find_files($fullname$pattern$callback); 

The next few lines could have some code added to them to not process files whose full path+name matches a particular pattern:

if(is_file($fullname) && preg_match($pattern$entry)) 
	
call_user_func($callback$fullname); 

In maliciouscodesnippets(), this code excludes one filename from the search. Other similar lines could be added to exclude other files by their names (but not, I think, based on their paths):

if(stripos($filename"lookforbadguys.php")) // DON'T FLAG THIS FILE WHICH I CALLED lookforbadguys.php 
	
return;  

I've noted that these code modifications could be made, but as it requires testing the results, it's not likely I'd get around to doing this until sometime in 2012.


Until then, your best bet is to let all files be processed, and ignore the results for the files whose report you don't care about.

Pages: « 1 2 3 4 5 6 7 8 9 10
Yahoo! Search
Search the web Search this site
Mazeguy Smilies Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!