Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit d2bdacf

Browse files
authored
Merge pull request #1 from ajilaag/develop
HTTPS & malware signature database
2 parents 55c2472 + d10c4fd commit d2bdacf

8 files changed

+95
-15
lines changed

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ RUN sed -i 's/^#Foreground .*$/Foreground true/g' /etc/clamav/clamd.conf \
1717
&& sed -i 's/^#TCPSocket .*$/TCPSocket 3310/g' /etc/clamav/clamd.conf \
1818
&& sed -i 's/^#Foreground .*$/Foreground true/g' /etc/clamav/freshclam.conf
1919

20-
RUN freshclam --quiet --no-dns --checks=2
20+
RUN freshclam --quiet --no-dns
2121

2222
# Build go package
2323
ADD . /go/src/clamav-rest/
24+
ADD ./server.* /etc/ssl/clamav-rest/
2425
RUN cd /go/src/clamav-rest && go build -v
2526

2627
COPY entrypoint.sh /usr/bin/
2728
RUN mv /go/src/clamav-rest/clamav-rest /usr/bin/ && rm -Rf /go/src/clamav-rest
2829

2930
EXPOSE 9000
31+
EXPOSE 9443
3032

3133
ENV MAX_SCAN_SIZE=100M
3234
ENV MAX_FILE_SIZE=25M
@@ -41,5 +43,6 @@ ENV MAX_PARTITIONS=50
4143
ENV MAX_ICONSPE=100
4244
ENV PCRE_MATCHLIMIT=100000
4345
ENV PCRE_RECMATCHLIMIT=2000
46+
ENV SIGNATURE_CHECKS=24
4447

4548
ENTRYPOINT [ "entrypoint.sh" ]

README.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ The following image tags are available:
3636

3737
Run clamav-rest docker image:
3838
```bash
39-
docker run -p 9000:9000 -itd --name clamav-rest ajilaag/clamav-rest
39+
docker run -p 9000:9000 -p 9443:9443 -itd --name clamav-rest ajilaag/clamav-rest
4040
```
4141

4242
Test that service detects common test virus signature:
43+
44+
**HTTP**
4345
```bash
4446
$ curl -i -F "[email protected]" http://localhost:9000/scan
4547
HTTP/1.1 100 Continue
@@ -52,7 +54,22 @@ Content-Length: 56
5254
{ Status: "FOUND", Description: "Eicar-Test-Signature" }
5355
```
5456
57+
**HTTPS**
58+
```bash
59+
$ curl -i -k -F "[email protected]" https://localhost:9443/scan
60+
HTTP/1.1 100 Continue
61+
62+
HTTP/1.1 406 Not Acceptable
63+
Content-Type: application/json; charset=utf-8
64+
Date: Mon, 28 Aug 2017 20:22:34 GMT
65+
Content-Length: 56
66+
67+
{ Status: "FOUND", Description: "Eicar-Test-Signature" }
68+
```
69+
5570
Test that service returns 200 for clean file:
71+
72+
**HTTP**
5673
```bash
5774
$ curl -i -F "[email protected]" http://localhost:9000/scan
5875

@@ -65,6 +82,21 @@ Content-Length: 33
6582

6683
{ Status: "OK", Description: "" }
6784
```
85+
**HTTPS**
86+
```bash
87+
$ curl -i -k -F "[email protected]" https://localhost:9443/scan
88+
89+
HTTP/1.1 100 Continue
90+
91+
HTTP/1.1 200 OK
92+
Content-Type: application/json; charset=utf-8
93+
Date: Mon, 28 Aug 2017 20:23:16 GMT
94+
Content-Length: 33
95+
96+
{ Status: "OK", Description: "" }
97+
```
98+
99+
68100
69101
## Status Codes
70102
- 200 - clean file = no KNOWN infections
@@ -94,6 +126,7 @@ Below is the complete list of available options that can be used to customize yo
94126
| `MAX_ICONSPE` | How many Icons in PE to scan - Default `100` |
95127
| `PCRE_MATCHLIMIT` | Maximum PCRE Match Calls - Default `100000` |
96128
| `PCRE_RECMATCHLIMIT` | Maximum Recursive Match Calls to PCRE - Default `2000` |
129+
| `SIGNATURE_CHECKS` | Check times per day for a new database signature. Must be between 1 and 50. - Default `24` |
97130
98131
## Networking
99132
@@ -108,7 +141,7 @@ Below is the complete list of available options that can be used to customize yo
108141
For debugging and maintenance purposes you may want access the containers shell.
109142
110143
```bash
111-
docker exec -it (whatever your container name is e.g. clamav) bash
144+
docker exec -it (whatever your container name is e.g. clamav-rest) /bin/sh
112145
```
113146
114147
# Developing
@@ -118,7 +151,7 @@ Build golang (linux) binary and docker image:
118151
```bash
119152
# env GOOS=linux GOARCH=amd64 go build
120153
docker build . -t clamav-go-rest
121-
docker run -p 9000:9000 -itd --name clamav-rest clamav-go-rest
154+
docker run -p 9000:9000 -p 9443:9443 -itd --name clamav-rest clamav-go-rest
122155
```
123156
124157
# References

centos.Dockerfile

+19-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,32 @@ RUN sed -i 's/^Example$/# Example/g' /etc/clamd.d/scan.conf \
2828
&& sed -i 's/^#TCPSocket .*$/TCPSocket 3310/g' /etc/clamd.d/scan.conf \
2929
&& sed -i 's/^#Foreground .*$/Foreground true/g' /etc/freshclam.conf
3030

31+
RUN freshclam --quiet --no-dns
32+
3133
# Build go package
3234
ADD . /go/src/clamav-rest/
35+
ADD ./server.* /etc/ssl/clamav-rest/
3336
RUN cd /go/src/clamav-rest/ && go build -v
3437

3538
COPY entrypoint.sh /usr/bin/
3639
RUN mv /go/src/clamav-rest/clamav-rest /usr/bin/ && rm -Rf /go/src/clamav-rest
3740

3841
EXPOSE 9000
39-
40-
RUN freshclam --quiet
42+
EXPOSE 9443
43+
44+
ENV MAX_SCAN_SIZE=100M
45+
ENV MAX_FILE_SIZE=25M
46+
ENV MAX_RECURSION=16
47+
ENV MAX_FILES=10000
48+
ENV MAX_EMBEDDEDPE=10M
49+
ENV MAX_HTMLNORMALIZE=10M
50+
ENV MAX_HTMLNOTAGS=2M
51+
ENV MAX_SCRIPTNORMALIZE=5M
52+
ENV MAX_ZIPTYPERCG=1M
53+
ENV MAX_PARTITIONS=50
54+
ENV MAX_ICONSPE=100
55+
ENV PCRE_MATCHLIMIT=100000
56+
ENV PCRE_RECMATCHLIMIT=2000
57+
ENV SIGNATURE_CHECKS=24
4158

4259
ENTRYPOINT [ "entrypoint.sh" ]

clamrest.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"strings"
1212
"time"
13+
1314
"github.com/dutchcoders/go-clamd"
1415
)
1516

@@ -157,6 +158,11 @@ func waitForClamD(port string, times int) {
157158

158159
func main() {
159160

161+
const (
162+
PORT = ":9000"
163+
SSL_PORT = ":9443"
164+
)
165+
160166
opts = make(map[string]string)
161167

162168
for _, e := range os.Environ() {
@@ -178,10 +184,9 @@ func main() {
178184
http.HandleFunc("/scanPath", scanPathHandler)
179185
http.HandleFunc("/", home)
180186

181-
//Listen on port PORT
182-
if opts["PORT"] == "" {
183-
opts["PORT"] = "9000"
184-
}
185-
fmt.Printf("Listening on port " + opts["PORT"])
186-
http.ListenAndServe(":"+opts["PORT"], nil)
187-
}
187+
// Start the HTTPS server in a goroutine
188+
go http.ListenAndServeTLS(SSL_PORT, "/etc/ssl/clamav-rest/server.crt", "/etc/ssl/clamav-rest/server.key", nil)
189+
190+
// Start the HTTP server
191+
http.ListenAndServe(PORT, nil)
192+
}

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ services:
55
mem_limit: 1048576000
66
image: ajilaag/clamav-rest
77
ports:
8-
- "9000:9000"
8+
- "9000:9000"
9+
- "9443:9443"

entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sed -i 's/^#MaxIconsPE .*$/MaxIconsPE '"$MAX_ICONSPE"'/g' /etc/clamav/clamd.conf
1616
sed -i 's/^#PCREMatchLimit.*$/PCREMatchLimit '"$PCRE_MATCHLIMIT"'/g' /etc/clamav/clamd.conf
1717
sed -i 's/^#PCRERecMatchLimit .*$/PCRERecMatchLimit '"$PCRE_RECMATCHLIMIT"'/g' /etc/clamav/clamd.conf
1818

19-
freshclam -d &
19+
freshclam --daemon --checks=$SIGNATURE_CHECKS &
2020
clamd &
2121
/usr/bin/clamav-rest &
2222

server.crt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIB2TCCAV8CCQDifaD7KfcXjzAKBggqhkjOPQQDBDBWMQswCQYDVQQGEwJDSDEQ
3+
MA4GA1UECAwHTHVjZXJuZTEPMA0GA1UEBwwGU3Vyc2VlMREwDwYDVQQKDAhhamls
4+
YSBBRzERMA8GA1UECwwIYWppbGEgQUcwHhcNMjAwMjA1MTI1MTQzWhcNMzAwMjAy
5+
MTI1MTQzWjBWMQswCQYDVQQGEwJDSDEQMA4GA1UECAwHTHVjZXJuZTEPMA0GA1UE
6+
BwwGU3Vyc2VlMREwDwYDVQQKDAhhamlsYSBBRzERMA8GA1UECwwIYWppbGEgQUcw
7+
djAQBgcqhkjOPQIBBgUrgQQAIgNiAARqaWNMhncO9fc3bhLHNvcpT+Oml4yXEMX3
8+
gUXb3SNeyW5dE74x6hxQQ04qIB/UmC5zi+USJmvrbUwm+nFehqBvn5S8aZgeXklL
9+
MpKFzXepzsgHIisYG3U943+7Fj6m67cwCgYIKoZIzj0EAwQDaAAwZQIxAKatG/Zw
10+
TR2yYRPExR8bFalQYle1JqNbHcfv8p2bqb9+ISqIaXmJde5S+5gvez0VOwIwKIpE
11+
gteclRk6IQy9NKxCsoflcMwXI4r45Tffi3PV7x2O4rMbPGVwyk4IGms9hb+S
12+
-----END CERTIFICATE-----

server.key

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN EC PARAMETERS-----
2+
BgUrgQQAIg==
3+
-----END EC PARAMETERS-----
4+
-----BEGIN EC PRIVATE KEY-----
5+
MIGkAgEBBDBZM2J/UKtGWJ5iu/VWRb5tUt2G41EcQKrgmrJT473hackaLP0C1peI
6+
ubjs6qbBmaigBwYFK4EEACKhZANiAARqaWNMhncO9fc3bhLHNvcpT+Oml4yXEMX3
7+
gUXb3SNeyW5dE74x6hxQQ04qIB/UmC5zi+USJmvrbUwm+nFehqBvn5S8aZgeXklL
8+
MpKFzXepzsgHIisYG3U943+7Fj6m67c=
9+
-----END EC PRIVATE KEY-----

0 commit comments

Comments
 (0)