|
9 | 9 |
|
10 | 10 | # Update Net::LDAP's initialize and new_connection method to honor a tracking proxies setting
|
11 | 11 | class Net::LDAP
|
| 12 | + WhoamiOid = '1.3.6.1.4.1.4203.1.11.3'.freeze |
| 13 | + |
| 14 | + # fix the definition for ExtendedResponse |
| 15 | + AsnSyntax[Net::BER::TAG_CLASS[:universal] + Net::BER::ENCODING_TYPE[:constructed] + 107] = :string |
| 16 | + |
12 | 17 | # Reference the old initialize method, and ensure `reload_lib -a` doesn't attempt to refine the method
|
13 | 18 | alias_method :_old_initialize, :initialize unless defined?(_old_initialize)
|
14 | 19 |
|
@@ -457,6 +462,40 @@ def modify(args)
|
457 | 462 |
|
458 | 463 | pdu
|
459 | 464 | end
|
| 465 | + |
| 466 | + # Monkeypatch upstream library to support the extended Whoami request. Delete |
| 467 | + # this after https://github.com/ruby-ldap/ruby-net-ldap/pull/425 is landed. |
| 468 | + # This is not the only occurrence of a patch for this functionality. |
| 469 | + def ldapwhoami |
| 470 | + ext_seq = [Net::LDAP::WhoamiOid.to_ber_contextspecific(0)] |
| 471 | + request = ext_seq.to_ber_appsequence(Net::LDAP::PDU::ExtendedRequest) |
| 472 | + |
| 473 | + message_id = next_msgid |
| 474 | + |
| 475 | + write(request, nil, message_id) |
| 476 | + pdu = queued_read(message_id) |
| 477 | + |
| 478 | + if !pdu || pdu.app_tag != Net::LDAP::PDU::ExtendedResponse |
| 479 | + raise Net::LDAP::ResponseMissingOrInvalidError, "response missing or invalid" |
| 480 | + end |
| 481 | + |
| 482 | + pdu |
| 483 | + end |
| 484 | +end |
| 485 | + |
| 486 | +class Net::LDAP::PDU |
| 487 | + # Monkeypatch upstream library to support the extended Whoami request. Delete |
| 488 | + # this after https://github.com/ruby-ldap/ruby-net-ldap/pull/425 is landed. |
| 489 | + # This is not the only occurrence of a patch for this functionality. |
| 490 | + def parse_extended_response(sequence) |
| 491 | + sequence.length.between?(3, 5) or raise Net::LDAP::PDU::Error, "Invalid LDAP result length." |
| 492 | + @ldap_result = { |
| 493 | + :resultCode => sequence[0], |
| 494 | + :matchedDN => sequence[1], |
| 495 | + :errorMessage => sequence[2], |
| 496 | + } |
| 497 | + @extended_response = sequence.last |
| 498 | + end |
460 | 499 | end
|
461 | 500 |
|
462 | 501 | module Rex
|
|
0 commit comments