This sub-class searches an HTML response for the SAML data
| 117 | |
| 118 | |
| 119 | class MySAMLParser(HTMLParser): |
| 120 | """ |
| 121 | This sub-class searches an HTML response for the SAML data |
| 122 | """ |
| 123 | |
| 124 | saml_response = "" |
| 125 | relay_state = "" |
| 126 | |
| 127 | def handle_starttag(self, tag, attrs): |
| 128 | if tag == "input": |
| 129 | found_saml = False |
| 130 | found_relay = False |
| 131 | for attr in attrs: |
| 132 | if ( |
| 133 | self.saml_response == "" |
| 134 | and attr[0] == "name" |
| 135 | and attr[1] == "SAMLResponse" |
| 136 | ): |
| 137 | found_saml = True |
| 138 | elif ( |
| 139 | self.relay_state == "" |
| 140 | and attr[0] == "name" |
| 141 | and attr[1] == "RelayState" |
| 142 | ): |
| 143 | found_relay = True |
| 144 | elif found_saml and attr[0] == "value": |
| 145 | self.saml_response = attr[1] |
| 146 | elif found_relay and attr[0] == "value": |
| 147 | self.relay_state = attr[1] |
| 148 | |
| 149 | |
| 150 | class Rapid7(object): |