|
1 | | - |
2 | | - |
3 | | -<div align="center"> |
4 | | - |
5 | | -<h1>VulnerableCode</h1> |
6 | | - |
7 | | - |
8 | | - |
9 | | -[](https://travis-ci.org/nexB/vulnerablecode) |
10 | | - |
11 | | -[](https://opensource.org/licenses/Apache-2.0) |
12 | | - |
13 | | -[](https://www.python.org/downloads/release/python-360/) |
14 | | - |
15 | | - |
16 | | - |
17 | | -[](https://gitter.im/aboutcode-org/vulnerablecode) |
18 | | - |
19 | | -[](http://makeapullrequest.com) |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | -</div> |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | -## The What |
32 | | - |
33 | | - |
34 | | - |
35 | | -VulnerableCode is a FOSS database of vulnerabilities and the FOSS packages they impact. It is made by the FOSS community to improve and secure the open source software ecosystem. |
36 | | - |
37 | | - |
38 | | - |
39 | | -## The Why |
40 | | - |
41 | | - |
42 | | - |
43 | | -The existing solutions are commercial proprietary vulnerability databases, which in itself does not make sense because the data is about FOSS. |
44 | | - |
45 | | - |
46 | | - |
47 | | -National Vulnerability Database which is the primary data source for all things security, is not particulary catered to address FOSS security issues, because: |
48 | | - |
49 | | - |
50 | | - |
51 | | -1. It predates explosion of FOSS software usage |
52 | | - |
53 | | -2. It's data format reflects commercial vendor-centric point of view, this is due to the usage of [CPE](https://nvd.nist.gov/products/cpe) to map vulnerabilities and the packages. |
54 | | - |
55 | | -3. CPEs are just not designed to map FOSS to vulnerabilities owing to their vendor-product centric semantics. This makes it really hard to answer the fundamental question "Is package foo vulnerable to vulnerability bar?" |
56 | | - |
57 | | - |
58 | | - |
59 | | -## The How |
60 | | - |
61 | | - |
62 | | - |
63 | | -VulnerableCode independently aggregates many software vulnerability data sources that can easily be recreated in a decentralized fashion. These data sources include security advisories published by distros, package managers etc. Due to this the data obtained is not generalized to apply for other ecosystems. This increases the accuracy as the same version of a package across different distros may or may not be vulnerable to some vulnerability. |
64 | | - |
65 | | - |
66 | | - |
67 | | -The packages are identified using [PURL](https://github.com/package-url/purl-spec) rather than CPEs. This makes it really easy to answer questions like "Is package foo vulnerable to vulnerability bar ? ". |
68 | | - |
69 | | - |
70 | | - |
71 | | -The web interface enables community curation of data by enabling addition of new packages, vulnerabilities and modifying the relationships between them as shown in GIF. Along with the web interface the API allows seamless consumption of the data. |
72 | | - |
73 | | - |
74 | | - |
75 | | -We also plan to mine for vulnerabilities which didn't receive any exposure due to various reasons like but not limited to the complicated procedure to receive CVE ID or not able to classify a bug as a security compromise. Check VulnerableCode at [Open Source Summit 2020](https://ossna2020.sched.com/event/c46p/why-is-there-no-free-software-vulnerability-database-philippe-ombredanne-aboutcodeorg-and-nexb-inc-michael-herzog-nexb-inc) |
76 | | - |
77 | | - |
78 | | -## Setting up VulnerableCode |
79 | | - |
80 | | -Clone the source code: |
81 | | - |
82 | | -``` |
83 | | -git clone https://github.com/nexB/vulnerablecode.git |
84 | | -cd vulnerablecode |
85 | | -``` |
86 | | - |
87 | | - |
88 | | -### Using Docker Compose |
89 | | - |
90 | | -The easiest way to set up VulnerableCode is by using the docker containers. |
91 | | -For this you need to have the following installed. |
92 | | - |
93 | | -- Docker Engine. Find instructions to install it [here](https://docs.docker.com/get-docker/) |
94 | | -- Docker Compose. Find instructions to install it [here](https://docs.docker.com/compose/install/#install-compose) |
95 | | - |
96 | | -Use `sudo docker-compose up` to start VulnerableCode. |
97 | | - |
98 | | -Access VulnerableCode at `http://localhost:8000/` or at `http://127.0.0.1:8000/` . |
99 | | - |
100 | | -Use `sudo docker-compose exec web bash` to access the VulnerableCode container. From here you can run access `manage.py` and run management commands to import data as specified below. |
101 | | - |
102 | | -### Without docker |
103 | | - |
104 | | - |
105 | | -**System requirements** |
106 | | - |
107 | | -- Python 3.8+ |
108 | | - |
109 | | -- PostgreSQL 9+ or [Docker](https://hub.docker.com/search/?type=edition&offering=community) |
110 | | - |
111 | | -- Compiler toolchain and development files for Python and PostgreSQL |
112 | | - |
113 | | - |
114 | | - |
115 | | -On Debian-based distros, these can be installed with `sudo apt install python3-venv python3-dev postgresql libpq-dev build-essential`. Leave out `postgresql` if you want to run it in Docker. |
116 | | - |
117 | | - |
118 | | - |
119 | | -**Database configuration** |
120 | | - |
121 | | - |
122 | | -- Create a user named `vulnerablecode`. Use `vulnerablecode` as password when prompted: |
123 | | - |
124 | | -`sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb --pwprompt vulnerablecode` |
125 | | - |
126 | | - |
127 | | -- Create a database named `vulnerablecode`: |
128 | | - |
129 | | -`createdb --encoding=utf-8 --owner=vulnerablecode --user=vulnerablecode --password --host=localhost --port=5432 vulnerablecode` |
130 | | - |
131 | | - |
132 | | - |
133 | | -**Application dependencies** |
134 | | - |
135 | | - |
136 | | - |
137 | | -Activate a virtualenv, install dependencies, and run the database migrations: |
138 | | - |
139 | | - |
140 | | - |
141 | | -``` |
142 | | -
|
143 | | -python3 -m venv venv |
144 | | -
|
145 | | -source venv/bin/activate |
146 | | -
|
147 | | -pip install -r requirements.txt |
148 | | -
|
149 | | -DJANGO_DEV=1 python manage.py migrate |
150 | | -
|
151 | | -``` |
152 | | - |
153 | | - |
154 | | - |
155 | | -The environment variable `DJANGO_DEV` is used to load settings suitable for development, defined in `vulnerablecode/dev.py`. If you don't want to type |
156 | | - |
157 | | -it every time use `export DJANGO_DEV=1` instead. |
158 | | - |
159 | | - |
160 | | - |
161 | | -When not running in development mode, an environment variable named `SECRET_KEY` needs to be set. The recommended way to generate this key is to use |
162 | | - |
163 | | -the code Django includes for this purpose: `SECRET_KEY=$(python -c "from django.core.management import utils; print(utils.get_random_secret_key())")`. |
164 | | - |
165 | | - |
166 | | - |
167 | | -## Tests |
168 | | - |
169 | | - |
170 | | - |
171 | | -``` |
172 | | -
|
173 | | -pycodestyle --exclude=migrations,settings.py,venv,lib_oval.py,test_ubuntu.py,test_suse.py,test_data_source.py --max-line-length=100 . |
174 | | -
|
175 | | -DJANGO_DEV=1 pytest |
176 | | -
|
177 | | -``` |
178 | | - |
179 | | -## Data import |
180 | | - |
181 | | - |
182 | | - |
183 | | -``` |
184 | | -
|
185 | | -DJANGO_DEV=1 python manage.py import --all |
186 | | -
|
187 | | -``` |
188 | | - |
189 | | - |
190 | | - |
191 | | -If you want to run the import periodically, you can use a systemd timer: |
192 | | - |
193 | | - |
194 | | - |
195 | | -``` |
196 | | -
|
197 | | -$ cat ~/.config/systemd/user/vulnerablecode.service |
198 | | -
|
199 | | - |
200 | | -
|
201 | | -[Unit] |
202 | | -
|
203 | | -Description=Update vulnerability database |
204 | | -
|
205 | | - |
206 | | -
|
207 | | -[Service] |
208 | | -
|
209 | | -Type=oneshot |
210 | | -
|
211 | | -Environment="DJANGO_DEV=1" |
212 | | -
|
213 | | -ExecStart=/path/to/venv/bin/python /path/to/vulnerablecode/manage.py import --all |
214 | | -
|
215 | | - |
216 | | -
|
217 | | -$ cat ~/.config/systemd/user/vulnerablecode.timer |
218 | | -
|
219 | | - |
220 | | -
|
221 | | -[Unit] |
222 | | -
|
223 | | -Description=Periodically update vulnerability database |
224 | | -
|
225 | | - |
226 | | -
|
227 | | -[Timer] |
228 | | -
|
229 | | -OnCalendar=daily |
230 | | -
|
231 | | - |
232 | | -
|
233 | | -[Install] |
234 | | -
|
235 | | -WantedBy=multi-user.target |
236 | | -
|
237 | | -``` |
238 | | - |
239 | | - |
240 | | - |
241 | | -Start it with |
242 | | - |
243 | | - |
244 | | - |
245 | | -``` |
246 | | -
|
247 | | -systemctl --user daemon-reload && systemctl --user start vulnerablecode.timer |
248 | | -
|
249 | | -``` |
250 | | - |
251 | | - |
252 | | - |
253 | | -## API |
254 | | - |
255 | | - |
256 | | - |
257 | | -Start the web server. |
258 | | - |
259 | | -In your browser access: |
260 | | - |
261 | | -``` |
262 | | -
|
263 | | -http://127.0.0.1:8000/api/docs |
264 | | -
|
265 | | -``` |
266 | | - |
267 | | -For full documentation about API endpoints. |
0 commit comments