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
b602dba9
Commit
b602dba9
authored
7 years ago
by
BorelEnzo
Browse files
Options
Downloads
Patches
Plain Diff
Create basic test: file size
parent
4fee284d
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Analyzer.php
+48
-48
48 additions, 48 deletions
src/Analyzer.php
src/test.php
+0
-1
0 additions, 1 deletion
src/test.php
src/util.php
+16
-15
16 additions, 15 deletions
src/util.php
tests/AnalyzerTest.php
+15
-11
15 additions, 11 deletions
tests/AnalyzerTest.php
with
79 additions
and
75 deletions
src/Analyzer.php
+
48
−
48
View file @
b602dba9
<?php
namespace
Analyzer
;
class
Analyzer
{
private
$fileName
;
private
$fileContent
;
function
__construct
(){}
function
__destruct
(){}
public
function
analyze
(
$pFileName
){
if
(
!
$pFileName
||
!
is_string
(
$pFileName
)){
$this
->
kill
(
"No file"
);
}
else
{
$this
->
fileName
=
$pFileName
;
$this
->
fileContent
=
file_get_contents
(
$this
->
fileName
);
}
class
Analyzer
{
private
$fileName
;
private
$fileContent
;
public
function
analyze
(
$pFileName
)
{
if
(
!
$pFileName
||
!
is_string
(
$pFileName
))
{
$this
->
kill
(
"No file"
);
}
else
{
$this
->
fileName
=
$pFileName
;
$this
->
fileContent
=
file_get_contents
(
$this
->
fileName
);
}
/**
* //FIXME kill properly
* @param string $message
*/
private
function
kill
(
$message
){
die
(
$message
);
}
/**
* Searches for non-ASCII characters, often used in obfuscated files
* @return number
*/
private
function
searchNonASCIIChars
(){
$count
=
0
;
for
(
$i
=
0
;
$i
<
strlen
(
$this
->
fileContent
);
$i
++
){
if
(
ord
(
$this
->
fileContent
[
$i
])
>
0x7f
){
$count
++
;
}
}
/**
* //FIXME kill properly
* @param string $message
*/
private
function
kill
(
$message
)
{
die
(
$message
);
}
/**
* Searches for non-ASCII characters, often used in obfuscated files
* @return number
*/
private
function
searchNonASCIIChars
()
{
$count
=
0
;
for
(
$i
=
0
;
$i
<
strlen
(
$this
->
fileContent
);
$i
++
)
{
if
(
ord
(
$this
->
fileContent
[
$i
])
>
0x7f
)
{
$count
++
;
}
return
$count
/
strlen
(
$this
->
fileContent
);
}
/**
* Wrapper for tests
* @param $func
* @return ? value of the called function
*/
public
function
testMe
(
$func
){
return
$this
->
$func
();
}
return
$count
/
strlen
(
$this
->
fileContent
);
}
/**
* Wrapper for tests
* @param $func
* @return ? value of the called function
*/
public
function
testMe
(
$func
)
{
return
$this
->
$func
();
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
src/test.php
+
0
−
1
View file @
b602dba9
<?php
$Æ
=
"test"
;
echo
$Æ
;
?>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/util.php
+
16
−
15
View file @
b602dba9
<?php
/**
* Apply the strpos function with an array of parameters
* @param string $haystack
* @param array $arrayOfWords words to search in the haystack
* @return int|boolean
*/
function
strposOnArray
(
$haystack
,
$arrayOfWords
)
{
if
(
is_array
(
$arrayOfWords
))
{
foreach
(
$arrayOfWords
as
$word
)
{
$pos
=
strpos
(
$haystack
,
$word
)
;
if
(
$pos
!==
false
)
{
return
$pos
;
}
/**
* Apply the strpos function with an array of parameters
* @param string $haystack
* @param array $arrayOfWords words to search in the haystack
* @return int|boolean
*/
function
strposOnArray
(
$haystack
,
$arrayOfWords
)
{
if
(
is_array
(
$arrayOfWords
)
)
{
foreach
(
$arrayOfWords
as
$word
)
{
$pos
=
strpos
(
$haystack
,
$word
);
if
(
$pos
!==
false
)
{
return
$pos
;
}
return
false
;
}
}
\ No newline at end of file
return
false
;
}
}
This diff is collapsed.
Click to expand it.
tests/AnalyzerTest.php
+
15
−
11
View file @
b602dba9
<?php
namespace
Tests
;
use
PHPUnit\Framework\TestCase
;
require_once
'../src/Analyzer.php'
;
namespace
Tests
;
use
PHPUnit\Framework\TestCase
;
use
Analyzer\Analyzer
;
require_once
'../src/Analyzer.php'
;
class
AnalyzerTest
extends
TestCase
{
class
AnalyzerTest
extends
TestCase
{
public
function
testTestMe
(){
$analyzer
=
new
\Analyzer
();
$analyzer
->
analyze
(
"../src/test.php"
);
$this
->
assertTrue
(
$analyzer
->
testMe
(
"searchNonASCIIChars"
)
>
0
);
}
public
function
testTestMe
()
{
$analyzer
=
new
Analyzer
();
$analyzer
->
analyze
(
"../src/test.php"
);
$this
->
assertTrue
(
$analyzer
->
testMe
(
"searchNonASCIIChars"
)
>
0
);
}
?>
\ No newline at end of file
}
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