Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webshell-detector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cylab
webshell-detector
Commits
d505a4bc
Commit
d505a4bc
authored
7 years ago
by
Enzo
Browse files
Options
Downloads
Patches
Plain Diff
Ajout de /doc & /tests/res. Début de détection de sign. basée sur PHPWebshellDetector
parent
1305d0b7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
index.php
+2
-2
2 additions, 2 deletions
index.php
src/Analyzer.php
+24
-2
24 additions, 2 deletions
src/Analyzer.php
src/util.php
+53
-1
53 additions, 1 deletion
src/util.php
tests/AnalyzerTest.php
+2
-2
2 additions, 2 deletions
tests/AnalyzerTest.php
with
81 additions
and
7 deletions
index.php
+
2
−
2
View file @
d505a4bc
<?php
require_once
'const.php'
;
require_once
'
src/
const.php'
;
require_once
'src/util.php'
;
//FIXME remove it
...
...
@@ -33,7 +33,7 @@
return
"Symlink are not allowed"
;
}
if
(
strposOnArray
(
$pFileName
,
array
(
" "
,
'"'
,
"'"
,
"&"
,
"/"
,
"
\\
"
,
"?"
,
"#"
,
chr
(
0
)))){
$this
->
kill
(
"File name contains a
lmo
st one bad char"
);
$this
->
kill
(
"File name contains a
t lea
st one bad char"
);
}
return
1
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Analyzer.php
+
24
−
2
View file @
d505a4bc
<?php
namespace
AnalyzerNS
;
require_once
'util.php'
;
class
Analyzer
{
private
$fileName
;
private
$fileContent
;
private
$tokens
;
public
function
analyze
(
$pFileName
)
{
...
...
@@ -14,10 +17,11 @@ class Analyzer
}
else
{
$this
->
fileName
=
$pFileName
;
$this
->
fileContent
=
file_get_contents
(
$this
->
fileName
);
$this
->
tokens
=
token_get_all
(
$this
->
fileContent
);
//print_r($this->tokens);
}
}
/**
* //FIXME kill properly
* @param string $message
...
...
@@ -27,6 +31,24 @@ class Analyzer
die
(
$message
);
}
/**
* Basic. Searches dangerous function names allowing to execute commands
* @return boolean. True if dangerous functions are found.
*/
private
function
searchExecCmdFunctions
()
{
$funcs
=
array
(
"exec"
,
"passthru"
,
"popen"
,
"proc_open"
,
"pcntl_exec"
,
"shell_exec"
,
"system"
);
if
(
strposOnArray
(
$this
->
fileContent
,
$funcs
)
===
false
)
{
foreach
(
$this
->
tokens
as
$token
)
{
if
(
!
is_array
(
$token
)
&&
$token
===
"`"
)
{
return
true
;
}
}
return
false
;
}
return
true
;
}
/**
* Searches for non-ASCII characters, often used in obfuscated files
* @return number
...
...
This diff is collapsed.
Click to expand it.
src/util.php
+
53
−
1
View file @
d505a4bc
<?php
namespace
Analyzer
;
namespace
Analyzer
NS
;
/**
* Apply the strpos function with an array of parameters
...
...
@@ -18,4 +18,56 @@ function strposOnArray($haystack, $arrayOfWords)
}
return
false
;
}
return
true
;
}
/**
* Removes all carriage returns and/or line feeds
* @param $string
* @return NULL|$string
*/
function
removeCRLF
(
$string
)
{
return
$string
?
str_replace
(
PHP_EOL
,
''
,
$string
)
:
null
;
}
/**
* Removes whites spaces if the are repeateds
* @param $string
* @return NULL|string without repeated white spaces
*/
function
removeMultiWhiteSpaces
(
$string
)
{
return
$string
?
preg_replace
(
'/\s{2,}/'
,
' '
,
$string
)
:
null
;
}
/**
* Removes all whites spaces
* @param $string
* @return NULL|string whitout any white spaces
*/
function
removeAllWhiteSpaces
(
$string
)
{
return
$string
?
preg_replace
(
'/\s+/'
,
' '
,
$string
)
:
null
;
}
/**
* Removew white spaces outside strings
* @param $string
* @return NULL|string
*/
function
removeWhiteSpacesOutsideString
(
$tokens
)
{
if
(
!
$tokens
)
{
return
null
;
}
$retString
=
''
;
foreach
(
$tokens
as
$x
)
{
if
(
!
is_array
(
$x
))
{
$retString
.
=
$x
;
}
else
{
$retString
.
=
(
is_integer
(
$x
[
0
])
&&
$x
[
0
]
==
T_WHITESPACE
?
' '
:
$x
[
1
]);
}
}
return
$retString
;
}
This diff is collapsed.
Click to expand it.
tests/AnalyzerTest.php
+
2
−
2
View file @
d505a4bc
...
...
@@ -12,7 +12,7 @@ class AnalyzerTest extends TestCase
public
function
testTestMe
()
{
$analyzer
=
new
Analyzer
();
$analyzer
->
analyze
(
__DIR__
.
"/
../src
/test.php"
);
$this
->
assertTrue
(
$analyzer
->
testMe
(
"search
NonASCIIChar
s"
)
>
0
);
$analyzer
->
analyze
(
__DIR__
.
"/
res
/test.php"
);
$this
->
assertTrue
(
$analyzer
->
testMe
(
"search
ExecCmdFunction
s"
)
>
0
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment