bandit/examples/telnetlib.py
Jamie Finnigan 1ef271e26e Introduce wildcards to blacklist_calls plugin
This change makes it so wildcards can be used in bandit.yaml when
configuring function calls that should be alerted on.  For example, it
allows 'telnetlib.*' to be set as a blacklist entry, and will then
alert on a call to telnetlib.Telnet() and any other functions in that
namespace.

It uses stdlib's fnmatch, which means the wildcards are Unix shell
style.

This change also hijacks the telnetlib import check, adding a wildcarded
blacklist calls check as described above and adjusting tests and
example naming accordingly.

Change-Id: I0ff5891282ab762fd3dfc0447b20028d81d9afef
2015-09-03 10:46:57 -07:00

20 lines
330 B
Python

import telnetlib
import getpass
host = sys.argv[1]
username = raw_input('Username:')
password = getpass.getpass()
tn = telnetlib.Telnet(host)
tn.read_until("login: ")
tn.write(username + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print(tn.read_all())