|
| 1 | +<!DOCTYPE qhelp PUBLIC |
| 2 | + "-//Semmle//qhelp//EN" |
| 3 | + "qhelp.dtd"> |
| 4 | +<qhelp> |
| 5 | + |
| 6 | +<overview> |
| 7 | +<p>Sockets can be used to communicate |
| 8 | +with other machines on a network. |
| 9 | +You can use the (IP address, port) pair |
| 10 | +to define the access restrictions for the socket you create. |
| 11 | +When using the built-in Python <code>socket</code> module |
| 12 | +(for instance, when building a message sender service |
| 13 | +or an FTP server data transmitter), |
| 14 | +one has to bind the port to some interface. |
| 15 | +When you bind the port to all interfaces |
| 16 | +using <code>0.0.0.0</code> as the IP address, |
| 17 | +you essentially allow it to accept connections from any IPv4 address |
| 18 | +provided that it can get to the socket via routing. |
| 19 | +Binding to all interfaces is therefore associated with security risks.</p> |
| 20 | +</overview> |
| 21 | + |
| 22 | +<recommendation> |
| 23 | +<p>Bind your service incoming traffic only to a dedicated interface. |
| 24 | +If you need to bind more than one interface |
| 25 | +using the built-in <code>socket</code> module, |
| 26 | +create multiple sockets (instead of binding to one socket to all interfaces).</p> |
| 27 | +</recommendation> |
| 28 | + |
| 29 | +<example> |
| 30 | +<p>In this example, two sockets are insecure because they are bound to all interfaces; |
| 31 | +one through the <code>0.0.0.0</code> notation |
| 32 | +and another one through an empty string <code>''</code>. |
| 33 | +</p> |
| 34 | +<sample src="BindToAllInterfaces.py" /> |
| 35 | +</example> |
| 36 | + |
| 37 | +<references> |
| 38 | + <li>Python reference: <a href="https://docs.python.org/3/library/socket.html#socket-families"> |
| 39 | + Socket families</a>.</li> |
| 40 | + <li>Python reference: <a href="https://docs.python.org/3.7/howto/sockets.html"> |
| 41 | + Socket Programming HOWTO</a>.</li> |
| 42 | + <li>Common Vulnerabilities and Exposures: <a href="https://nvd.nist.gov/vuln/detail/CVE-2018-1281"> |
| 43 | + CVE-2018-1281 Detail</a>.</li> |
| 44 | +</references> |
| 45 | +</qhelp> |
0 commit comments