Skip to content

Commit 2c423ba

Browse files
author
Felipe \"Zimmerle\" Costa
committed
iis: Adds ssdeep support
1 parent d287029 commit 2c423ba

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

apache2/re_variables.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,7 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
11601160
}
11611161
/* If we had a match add this argument to the collection. */
11621162
if (match) {
1163-
static int buf_size = 1024;
1164-
char buf[buf_size];
1163+
char buf[1024];
11651164
FILE *file;
11661165
size_t nread;
11671166
char *full_content = NULL;
@@ -1173,7 +1172,7 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
11731172
continue;
11741173
}
11751174

1176-
while ((nread = fread(buf, 1, buf_size-1, file)) > 0)
1175+
while ((nread = fread(buf, 1, 1023, file)) > 0)
11771176
{
11781177
total_lenght += nread;
11791178
buf[nread] = '\0';

iis/Makefile.win

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
LIBS = $(APACHE)\lib\libapr-1.lib \
1111
$(APACHE)\lib\libaprutil-1.lib \
1212
$(PCRE)\pcre.lib \
13+
$(SSDEEP)\fuzzy.lib \
1314
$(LIBXML2)\win32\bin.msvc\libxml2.lib \
1415
"kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" \
1516
"oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "ws2_32.lib" \
1617
"iphlpapi.lib"
17-
1818
###########################################################################
1919
###########################################################################
2020

@@ -23,11 +23,13 @@ LINK = link.exe
2323

2424
MT = mt
2525

26-
DEFS = /nologo /O2 /LD /W3 /wd4244 /wd4018 -DWIN32 -DWINNT -Dinline=APR_INLINE -DAP_DECLARE_STATIC -D_MBCS -D$(VERSION)
26+
DEFS = /nologo /O2 /LD /W3 /wd4244 /wd4018 -DWITH_YAJL -DWIN32 -DWINNT -Dinline=APR_INLINE -DAP_DECLARE_STATIC -D_MBCS -D$(VERSION)
2727

2828
DLL = ModSecurityIIS.dll
2929

3030
INCLUDES = -I. -I.. \
31+
-I$(YAJL)\.. \
32+
-I$(SSDEEP) \
3133
-I$(PCRE)\include -I$(PCRE) \
3234
-I$(LIBXML2)\include \
3335
-I$(APACHE)\include \
@@ -47,6 +49,16 @@ LIBS = $(LIBS) $(YAJL)\lib\yajl.lib
4749
DEFS=$(DEFS) -DWITH_YAJL
4850
INCLUDES = $(INCLUDES) -I$(YAJL)\include -I$(YAJL) \
4951
!ENDIF
52+
53+
# ssdeep is optional
54+
!IF "$(SSDEEP)" != ""
55+
LIBS = $(LIBS) $(SSDEEP)\fuzzy.lib
56+
DEFS=$(DEFS) -DWITH_SSDEEP
57+
INCLUDES = $(INCLUDES) -I$(SSDEEP)\include -I$(SSDEEP) \
58+
!ENDIF
59+
60+
61+
5062

5163
CFLAGS= -MD /Zi $(INCLUDES) $(DEFS)
5264

@@ -60,6 +72,7 @@ OBJS1 = mod_security2.obj apache2_config.obj apache2_io.obj apache2_util.obj \
6072
msc_release.obj msc_crypt.obj msc_tree.obj \
6173
msc_status_engine.obj \
6274
msc_json.obj
75+
6376
OBJS2 = api.obj buckets.obj config.obj filters.obj hooks.obj regex.obj server.obj
6477
OBJS3 = main.obj moduleconfig.obj mymodule.obj
6578
OBJS4 = libinjection_html5.obj \

iis/build_dependencies.bat

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@set APACHE_BIN32=httpd-2.4.6-win32-VC11.zip
1919
@set APACHE_BIN64=httpd-2.4.6-win64-VC11.zip
2020
@set YAJL=lloyd-yajl-f4b2b1a.zip
21+
@set SSDEEP=ssdeep-2.10.tar.gz
22+
@set SSDEEP_BIN=ssdeep-2.10.zip
2123

2224
:: @set VCARGS32="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
2325
:: @set VCARGS64="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"
@@ -47,12 +49,11 @@ call cl 2>&1 | findstr /C:"x64"
4749
@call dependencies/build_apache.bat
4850
@if NOT (%ERRORLEVEL%) == (0) goto build_failed_apache
4951
@cd "%CURRENT_DIR%"
50-
echo "c"
52+
5153
@echo # pcre. - %PCRE%
5254
@call dependencies/build_pcre.bat
5355
@if NOT (%ERRORLEVEL%) == (0) goto build_failed_pcre
5456
@cd "%CURRENT_DIR%"
55-
echo "b"
5657

5758
@echo # zlib - %ZLIB%
5859
@call dependencies/build_zlib.bat
@@ -79,6 +80,11 @@ echo "b"
7980
@if NOT (%ERRORLEVEL%) == (0) goto build_failed_yajl
8081
@cd "%CURRENT_DIR%"
8182

83+
@echo # ssdeep - %SSDEEP%
84+
@call dependencies/build_ssdeep.bat
85+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed_ssdeep
86+
@cd "%CURRENT_DIR%"
87+
8288
@echo All dependencies were built successfully.
8389
@cd "%CURRENT_DIR%"
8490
@exit /B 0
@@ -119,6 +125,10 @@ echo "b"
119125
@echo Failed to setup %YAJL%...
120126
@goto failed
121127

128+
:build_failed_ssdeep
129+
@echo Failed to setup %SSDEEP%...
130+
@goto failed
131+
122132
:failed
123133
@cd %CURRENT_DIR%
124134
@exit /B 1

iis/build_modsecurity.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ set CURRENT_DIR=%cd%
1515
cd ..\apache2
1616
del *.obj *.dll *.lib
1717
del libinjection\*.obj libinjection\*.dll libinjection\*.lib
18-
NMAKE -f Makefile.win APACHE=..\iis\%DEPENDENCIES_DIR%\Apache24 PCRE=..\iis\%DEPENDENCIES_DIR%\pcre LIBXML2=..\iis\%DEPENDENCIES_DIR%\libxml2 LUA=..\iis\%DEPENDENCIES_DIR%\lua\src VERSION=VERSION_IIS YAJL=..\iis\%DEPENDENCIES_DIR%\yajl\build\yajl-2.0.1
18+
NMAKE -f Makefile.win APACHE=..\iis\%DEPENDENCIES_DIR%\Apache24 PCRE=..\iis\%DEPENDENCIES_DIR%\pcre LIBXML2=..\iis\%DEPENDENCIES_DIR%\libxml2 LUA=..\iis\%DEPENDENCIES_DIR%\lua\src VERSION=VERSION_IIS YAJL=..\iis\%DEPENDENCIES_DIR%\yajl\build\yajl-2.0.1 SSDEEP=..\iis\%DEPENDENCIES_DIR%\ssdeep
1919
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
2020

2121
@echo mlogc...
2222
cd ..\mlogc
2323
del *.obj *.dll *.lib
2424
nmake -f Makefile.win clean
25-
nmake -f Makefile.win APACHE=..\iis\%DEPENDENCIES_DIR%\Apache24 PCRE=..\iis\%DEPENDENCIES_DIR%\pcre CURL=..\iis\%DEPENDENCIES_DIR%\curl VERSION=VERSION_IIS
25+
nmake -f Makefile.win APACHE=..\iis\%DEPENDENCIES_DIR%\Apache24 PCRE=..\iis\%DEPENDENCIES_DIR%\pcre CURL=..\iis\%DEPENDENCIES_DIR%\curl YAJL=..\iis\%DEPENDENCIES_DIR%\yajl SSDEEP=..\iis\%DEPENDENCIES_DIR%\ssdeep VERSION=VERSION_IIS
2626
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
2727

2828
@echo iis...
2929
cd ..\iis
3030
del *.obj *.dll *.lib
3131
nmake -f Makefile.win clean
32-
NMAKE -f Makefile.win APACHE=..\iis\%DEPENDENCIES_DIR%\Apache24 PCRE=..\iis\%DEPENDENCIES_DIR%\pcre LIBXML2=..\iis\%DEPENDENCIES_DIR%\libxml2 LUA=..\iis\%DEPENDENCIES_DIR%\lua\src VERSION=VERSION_IIS YAJL=..\iis\%DEPENDENCIES_DIR%\yajl\build\yajl-2.0.1
32+
NMAKE -f Makefile.win APACHE=..\iis\%DEPENDENCIES_DIR%\Apache24 PCRE=..\iis\%DEPENDENCIES_DIR%\pcre LIBXML2=..\iis\%DEPENDENCIES_DIR%\libxml2 LUA=..\iis\%DEPENDENCIES_DIR%\lua\src VERSION=VERSION_IIS YAJL=..\iis\%DEPENDENCIES_DIR%\yajl\build\yajl-2.0.1 SSDEEP=..\iis\%DEPENDENCIES_DIR%\ssdeep
3333
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
3434

3535
cd %CURRENT_DIR%

iis/dependencies/build_ssdeep.bat

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cd "%WORK_DIR%"
2+
3+
@if NOT EXIST "%SOURCE_DIR%\%SSDEEP%" goto build_failed
4+
5+
@7z.exe x "%SOURCE_DIR%\%SSDEEP_BIN%"
6+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
7+
@7z.exe x "%SOURCE_DIR%\%SSDEEP%" -so | 7z.exe x -aoa -si -ttar
8+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
9+
10+
set SSDEEP_DIR=%SSDEEP_BIN:~0,-4%
11+
12+
move "%SSDEEP_DIR%" "ssdeep"
13+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
14+
cd "%WORK_DIR%\ssdeep\"
15+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
16+
17+
@set SSDEEP_ARCH="x86"
18+
@call cl 2>&1 | findstr /C:"x64"
19+
@if (%ERRORLEVEL%) == (0) set SSDEEP_ARCH="x64"
20+
21+
lib /machine:%SSDEEP_ARCH% /def:fuzzy.def
22+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
23+
24+
copy /y "%WORK_DIR%\ssdeep\fuzzy.dll" "%OUTPUT_DIR%"
25+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
26+
copy /y "%WORK_DIR%\ssdeep\fuzzy.def" "%OUTPUT_DIR%"
27+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
28+
copy /y "%WORK_DIR%\ssdeep\fuzzy.lib" "%OUTPUT_DIR%"
29+
@if NOT (%ERRORLEVEL%) == (0) goto build_failed
30+
31+
32+
@exit /B 0
33+
34+
:build_failed
35+
@echo Problems during the building phase
36+
@goto failed
37+
38+
:failed
39+
@exit /B 1

0 commit comments

Comments
 (0)