+
    4SsiCS                       ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
HtHtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIHt ^ R	IHtHtHt ^ R
IHt ^ RIHt ^ RIH t  ^ RIH!t! ^ RI"H#t# ^ RI$t$^ RI%H&t&H't'H(t( ^ RI)H*t* ^ RI+H,t,H-t-H.t.H/t/ ^ RI0H1t1 ^ RI2H3t3 ^ RI2H4t4 ^ RI5H6t6 ^ RI7H8t8 ^ RI9t9^t:^t;Rt<Rt=RRRRRRRRRRRRRRRRRR/	t>RRRRRRRRRRRRRRRR/t?0 Rmt@R$tAR]A,          tBRtC^ tD]8! ]ER%7      tFR& tGR' tHR( tI ! R) R*]J4      tK ! R+ R,]L4      tMR- tNR. tO ! R/ R0]L4      tP ! R1 R2]L4      tQ ! R3 R4]L4      tR ! R5 R6]R4      tSRR7 ltTR8 tUR9 tVR: tW ! R; R<]L4      tXRR= ltY/ RRbR>R?bR@R?bRR?bR!R?bRR?bRRbRAR?bRBR?bRR?bRCR?bRDR?bR"RbR#RbRER?bR RbtZ/ RRFbRRGbRRHbRRIbRRJbRRKbRRLbRRMbRRNbRRObRRPbRRQbRRRbRRSbRRTbRRUbRRVb/ RRWbRRXbRRYbRRZbRR[bRR\bRR]bRR^bRR_bRR`bRRabRRbbRRcbRRLbRRdbRRMbRRebC/ RRfbRRgbRRhbRRibRRjbRRkbRRlbRRVbRRWbRRmbRRnbRRobRRpbRRqbRRrbRRsbRRtbC/ RRubRRvbRRwbRRxbRRybRRzbRR{bRR|bRR}bRR~bRRbRRbER RbERRbERRbERRbERRbC/ ERRbERRbERRbERRbRRbER	RbER
RbERRbERRbERRbERRbERRbERRbERRbERRbERRbERRbCERRERRERRzERRERRERRERRERR/Ct[R t\R t]ERR lt^ERR lt_ERR lt`R taR tbR tc]! RER 4      tdR teER!R ltfR tgR thR tiER"R ltjR tkER!R ltlER!R ltmR tnR toR tpER!R ltq ! R R]L4      trR tsR ttR tuR tvR twR txR# (#      N)ECHILDESRCH)OrderedDictCounterdefaultdict
namedtuple)query)traffic_packets)SamDB)LdbError)ClientConnection)securitydrsuapilsa)netlogon)netr_Authenticator)srvsvc)samr)
drs_DsBind)CredentialsDONT_USE_KERBEROSMUST_USE_KERBEROS)system_session)UF_NORMAL_ACCOUNTUF_SERVER_TRUST_ACCOUNTUF_TRUSTED_FOR_DELEGATIONUF_WORKSTATION_TRUST_ACCOUNT)SEC_CHAN_BDC)gensec)sd_utils)
get_string)get_samba_loggerga2U0*3?-dns      ?smbldapcldapdcerpc11nbnssmb2browsersmb_netlogong      $@)namec                    V \         8:  dS   V'       g   \        V\        P                  R7       R# \        V\	        V4      ,          \        P                  R7       R# R# )a}  Print a formatted debug message to standard error.


:param level: The debug level, message will be printed if it is <= the
              currently set debug level. The debug level can be set with
              the -d option.
:param msg:   The message to be logged, can contain C-Style format
              specifiers
:param args:  The parameters required by the format specifiers
fileN)DEBUG_LEVELprintsysstderrtuple)levelmsgargss   &&*7/usr/lib/python3/dist-packages/samba/emulate/traffic.pydebugr<   e   s9     #CJJ'#d##**5	     c                 n   \         P                  ! ^R7      p\        RV^ ,          ^,          : RV^ ,          ^,          : R2R\        P                  R7       V  F  p\        V\        P                  R7       K   	  \        \        P                  R7       \        P                  P                  4        R# )zKPrint an unformatted log message to stderr, containing the line number
    )limit z	:[01;33mz [00m)endr2   r1   N)	tracebackextract_stackr4   r5   r6   flush)r:   tbas   *  r;   debug_linenorG   w   sz     
	 	 q	)B	!!uQxxAq39<zz acjj! 	szzJJr=   c                   a V '       d>   ^pV  F  pV^,          pW,          pV^,          pK  	  R^V,           ,          oV3R lpV# R pV# )zReturn a function that prints a coloured line to stderr. The colour
of the line depends on a sort of hash of the integer arguments.z
[38;5;%dmc                  x   < \         ^ 8  d.   V  F%  p\        S: V: R2\        P                  R7       K'  	  R# R# )r   z[00mr1   Nr3   r4   r5   r6   )r:   rF   prefixs   * r;   prandom_colour_print.<locals>.p   s,    QAFA6SZZH  r=   c                  h    \         ^ 8  d'   V  F  p\        V\        P                  R7       K   	  R# R# )r   r1   NrJ   )r:   rF   s   * r;   rL   rM      s&    QA!#**-  r=    )seedssxrL   rK   s   &   @r;   random_colour_printrS      sY     AGAFAHA  !BF+	I H	.
 Hr=   c                       ] tR t^tRtR# )FakePacketErrorrO   N)__name__
__module____qualname____firstlineno____static_attributes__rO   r=   r;   rU   rU      s    r=   rU   c                   |   a  ] tR t^t o RtRtR t]R 4       tRR lt	R t
R tR tR tR	 tR
 tR tRR ltRtV tR# )PacketzDetails of a network packetc
                    Wn         W n        W0n        W@n        WPn        W`n        Wpn        Wn        Wn        V P                  V P                  8  d    V P                  V P                  3V n	        R # V P                  V P                  3V n	        R # N
	timestampip_protocolstream_numbersrcdestprotocolopcodedescextra	endpoints)
selfr`   ra   rb   rc   rd   re   rf   rg   rh   s
   &&&&&&&&&&r;   __init__Packet.__init__   si    "&*	 	
88dii"hh		2DN"ii2DNr=   c                    VP                  R 4      P                  R4      pVR,          w  ppppppp	p
VR,          p\        V4      p\        V4      p\        V4      pV ! W4WVVWW4	      # )
	:N   N:rp   NN)rstripsplitfloatint)clslinefieldsr`   ra   rb   rc   rd   re   rf   rg   rh   s   &&          r;   	from_linePacket.from_line   s}    T"((. 								r
)$	#h4y9=tT2 	2r=   c                &   RP                  V P                  4      pV P                  V,           pTRTV P                  V P                  ;'       g    RV P
                  V P                  V P                  V P                  V P                  V3	,          3# )z5Format the packet as a traffic_summary line.
        ro   z%f	%s	%s	%d	%d	%s	%s	%s	%s )
joinrh   r`   ra   rb   rc   rd   re   rf   rg   )rj   time_offsetrh   ts   &&  r;   
as_summaryPacket.as_summary   s     		$**%NN[(7!!##))r	 	 		r=   c                ^   R V P                   V P                  V P                  V P                  ;'       g    RV P                  V P
                  V P                  V P                  V P                  '       d1   RRP                  V P                  4      ,           R,           3	,          # R3	,          # )z:%.3f: %d -> %d; ip %s; strm %s; prot %s; op %s; desc %s %sr#      «r@      »r{   )
r`   rc   rd   ra   rb   re   rf   rg   rh   r|   rj   s   &r;   __str__Packet.__str__   s    L499d6F6F6M6M###T]]DKK8<


$$**--4MM 	N IKMM 	Nr=   c                    R V ,          # )z<Packet @%s>rO   r   s   &r;   __repr__Packet.__repr__   s    $$r=   c                    V P                  V P                  V P                  V P                  V P                  V P
                  V P                  V P                  V P                  V P                  4	      # r^   )
	__class__r`   ra   rb   rc   rd   re   rf   rg   rh   r   s   &r;   copyPacket.copy   sU    ~~dnn".."00"hh"ii"mm"kk"ii"jj* 	*r=   c                @    V P                   : R V P                  : 2pV# ):re   rf   )rj   r~   s   & r;   as_packet_typePacket.as_packet_type   s    }}dkk2r=   c                    V P                   V P                  3pV\        9   d   \        V,          # V\        9   d   \        V,          ) # R# )zA positive number means we think it is a client; a negative number
means we think it is a server. Zero means no idea. range: -1 to 1.
        )re   rf   CLIENT_CLUESSERVER_CLUES)rj   keys   & r;   client_scorePacket.client_score   sB     }}dkk*,$$, %%%r=   c           
        RV P                   : RV P                  : 2p \        \        V4      pT P                   R8w  d   \        ^RTP                  : RT: 24       \        P                  ! 4       p T! YT4      '       dT   \        P                  ! 4       pYv,
          p\        R	YqP                  T P                   T P                  T3,          4       R# R#   \         d9   p\        RTP                  : RT: 2\        P                  R7        Rp?R# Rp?ii ; i  \         d]   p\        P                  ! 4       pYv,
          p\        R
YqP                  T P                   T P                  Y3,          4        Rp?R# Rp?ii ; i)zSend the packet over the network, if required.

Some packets are ignored, i.e. for  protocols not handled,
server response messages, or messages that are generated by the
protocol layer associated with other packets.
packet__zConversation(z) Missing handler r1   Nkerberosz) Calling handler z%f	%s	%s	%s	%f	True	z%f	%s	%s	%s	%f	False	%s)re   rf   getattrr
   AttributeErrorr4   conversation_idr5   r6   r<   time	Exception)	rj   conversationcontextfn_namefnestartrA   durations	   &&&      r;   playPacket.play  s?    %)MM4;;?	'2B ==J&!"22G= > 			.$g.. iik;288$--{{H.. / /  	//:zz# 		,  	.))+C{H144dmm;;-- . .	.s1   C 5A D D$-DDF*AFFc                <    V P                   VP                   ,
          # r^   r`   rj   others   &&r;   __cmp__Packet.__cmp__+  s    ~~//r=   Nc                B    \        V P                  V P                  4      # r^   )is_a_real_packetre   rf   )rj   missing_packet_statss   &&r;   is_really_a_packetPacket.is_really_a_packet.  s    t{{;;r=   )
rg   rd   ri   rh   ra   rf   re   rc   rb   r`   r_   )r   r^   )rV   rW   rX   rY   __doc__	__slots__rk   classmethodrx   r   r   r   r   r   r   r   r   r   rZ   __classdictcell____classdict__s   @r;   r\   r\      s\     %	I3  2 2& N%	*	&.P0< <r=   r\   c                   V \         9   d   R# V R8X  d
   VR8X  d   R# RV : RV: 2p\        \        VR4      pVf/   \        P	                  RV,          \
        P                  R7       R# V\        P                  J d   R# R	# )
z\Is the packet one that can be ignored?

If so removing it will have no effect on the replay
Fr'   r{   r   r   Nzmissing packet %sr1   T)SKIPPED_PROTOCOLSr   r
   LOGGERr<   r5   r6   null_packet)re   rf   r   r   s   &&  r;   r   r   2  sp    
 $$6fl (&1G	'4	0B	z(72D	_(((r=   c                >    V R8X  d   R# W3R9   d   R# \        W4      # )zReturn true if a packet generates traffic in its own right. Some of
these will generate traffic in certain contexts (e.g. ldap unbind
after a bind) but not if the conversation consists only of these packets.
waitF)r   r{   r'   2r)   15r)   16)r   r   s   &&r;   is_a_traffic_generating_packetr   H  s/    
 6  
 H--r=   c                     a  ] tR tRt o RtRRRRRRRRRR]P                  P                  R4      RR3R ltR t	R t
R tR	 tR
 tR tRR ltRR ltRR ltRR ltRR ltRR ltRR ltRR ltR tR tR tR tRtV tR# )ReplayContextiZ  a7  State/Context for a conversation between an simulated client and a
server. Some of the context is shared amongst all conversations
and should be generated before the fork, while other context is
specific to a particular conversation and should be generated
*after* the fork, in generate_process_local_config().
NDOMAINc                   Wn         R V n        W0n        W n        V'       d   \        V n        M\        V n        Wn        Wn        Wn	        Wn
        Wpn        Wn        VP                  R4      V n        Wn        WPn        RV n        RV n        RV n        RV n        RV n        RV n        RV n        RV n        W@n        V P5                  4        R # )NrealmF)servernetlogon_connectioncredslpr   kerberos_stater   oubase_dndomainstatsdirglobal_tempdir
domain_sidgetr   instance_idbadpassword_frequencylast_lsarpc_badlast_lsarpc_named_badlast_simple_bind_badlast_bind_badlast_srvsvc_badlast_drsuapi_badlast_netlogon_badlast_samlogon_badtotal_conversationsgenerate_ldap_search_tables)rj   r   r   r   r   r   prefer_kerberostempdirr   r   r   r   r   r   s   &&&&&&&&&&&&&&r;   rk   ReplayContext.__init__a  s     )/(, (-
(*"3D"3D(*(/(.(0(/(2(*w
(3 )>"(-(-"(-!(-(-(-(-(-(; ((*r=   c                   \        4       p\        R V P                  ,          VV P                  V P                  R7      pVP                  VP                  4       \        P                  R.R.R7      p/ pR. /pV F  p\        VP                  4      pRP                  R VP                  R4       4       4      P                  4       pVP                  V. 4      p	V	P                  V4       VP!                  R4      '       g   K  VR,          P                  V4       K  	  \#        VP%                  4       4       F{  p
V
RR	 R
8w  d   K  V
R	R pVRR	 R
8X  d   VR	R pK  \'        ^4       FG  pVR
,          pW8w  d,   W9   d&   \)        RV
: RV: 2\*        P,                  R7       K=  WJ,          WK&   KI  	  K}  	  W@n        WPn        / V n        VP                  VP                  4       \        P                  R.RR7      pRP                  R V 4       4      pRP5                  V4      V P2                  R&   RpR F)  pVRP5                  WP                  4       4      ,          pK+  	  RP5                  V4      V P2                  R&   RV P2                  R&   VP                  R\        P6                  R.R7      pRP5                  V^ ,          R,          4      V P2                  R&   R	# )	ldap://%s)urlsession_infocredentialsr   zpaged_results:1:1000dn)scopecontrolsattrsinvocationId,c              3   N   "   T F  qP                  4       R ,          x  K  	  R# 5i):N   NN)lstrip.0rR   s   & r;   	<genexpr><ReplayContext.generate_ldap_search_tables.<locals>.<genexpr>  s     E}!xxz"~~}s   #%zCN=NTDS Settings,Nz,DCzdn_map collision r@   r1   z"(objectclass=groupPolicyContainer))r   r   
expressionr{   c              3   R   "   T F  pR P                  VR,          4      x  K  	  R# 5i)z(distinguishedName={0})r   N)format)r   r9   s   & r;   r   r     s%     XTWS6==c$iHHTWs   %'z(|{0})gPCFileSysPathz(distinguishedName={0}{1})gpLinkz'(objectCategory=pKICertificateTemplate)pKIExtendedKeyUsagehighestCommittedUSN)r   r   z(usnChanged>={0})
usnChanged)zDomain Controllers,ztraffic_replay,r{   )r   r   r   r   r   search	domain_dnldbSCOPE_SUBTREEstrr   r|   rr   upper
setdefaultappend
startswithlistkeysranger4   r5   r6   dn_mapattribute_clue_mapsearch_filtersr   
SCOPE_BASE)rj   sessiondbresr  r  rr   patternr$   krL   i
gpos_by_dnou_strr   s   &               r;   r   )ReplayContext.generate_ldap_search_tables  s    "{T[[0 '#zzgg
 ii!//"8!9#f  & B
 AQTTBhhErxx}EEKKMG##GR0CJJrN}}011">299"=  fkkm$Av#2ABC&E/crF1XU
6aka;"zz+"I	  % "4
 ! iic.?.?v#G  IWWXTWXX
 19
0K,- @B299"llnMMF A(0(?H%
 6 	12
 ii#..9N8OiP&&s1v.C'DE 	L)r=   c                   V P                   P                  4        F  pWA9   g   K  V P                   V,          u # 	  VR 8X  dF   \        P                  ! 4       V P                  ,          p\	        V P
                  V4      pRV,          # R# )zDC,DCz((&(sAMAccountName=%s)(objectClass=user))z(objectClass=*))r  r  randomr   	user_namer   )rj   r   dn_sigr   r   random_user_idaccount_names   &&&&   r;   guess_search_filter!ReplayContext.guess_search_filter  su     &&++-C|**3// . W#]]_t/G/GGN$T%5%5~FL=LL !r=   c                >   . V n         . V n        . V n        . V n        . V n        . V n        . V n        VP                  V n        VP                  V n        VP                  V n	        VP                  V n
        \        V P                  R VP                  ,          4      V n        V P                  P!                  RV P                  4       V P                  P!                  RV P                  4       V P                  P!                  RV P                  4       V P                  P!                  RR4       RV n        RV P                  : RV P$                  : 2V n        RV P                  : RV P$                  : 2V n        V P+                  4        V P-                  4        R	# )
zconversation-%dzprivate dirzlock dirzstate directoryztls verify peerno_checkz/root/ncalrpc_as_systemcn=r   N)ldap_connectionsdcerpc_connectionslsarpc_connectionslsarpc_connections_nameddrsuapi_connectionssrvsvc_connectionssamr_contextsnetbios_namemachinepassusernameuserpassmk_masked_dirr   r   r   r   setremoteAddressr   samlogon_dnuser_dngenerate_machine_credsgenerate_user_creds)rj   accountr   s   &&&r;   generate_process_local_config+ReplayContext.generate_process_local_config  sB   (*(*(*(*%(* (*(*(/(<(<(/(;(;(/(8(8(/(8(8$T%8%8%6%1%A%A&BC 	M4<<0J-%t||4%z26#00$'';  $}}dgg7 	##%  "r=   c                    V'       gE   V P                   '       d1   \        P                  ! 4       V P                   8  d    V! V4       RpMRpV! V4      pWT3#   \         d     Li ; i)a  Execute the supplied logon function, randomly choosing the
bad credentials.

Based on the frequency in badpassword_frequency randomly perform the
function with the supplied bad credentials.
If run with bad credentials, the function is re-run with the good
credentials.
failed_last_time is used to prevent consecutive bad credential
attempts. So the over all bad credential frequency will be lower
than that requested, but not significantly.
TF)r   r!  r   )rj   fgoodbadfailed_last_timeresults   &&&&& r;   with_random_bad_credentials)ReplayContext.with_random_bad_credentials  si      ***$"<"<<cF
 $( #( 4)) !  s    A A&%A&c                P   \        4       V n        V P                  P                  V P                  4       V P                  P	                  V P
                  4       V P                  P                  V P                  4       V P                  P                  V P                  4       V P                  P                  V P                  4       V P                  P                  V P                  4       \        4       V n        V P                  P                  V P                  4       V P                  P	                  V P
                  4       V P                  P                  V P                  RR 4       V P                  P                  V P                  4       V P                  P                  V P                  4       \        4       V n        V P                  P                  V P                  4       V P                  P	                  V P
                  4       V P                  P                  V P                  4       V P                  P                  V P                  4       V P                  P!                  V P                  P#                  4       \$        P&                  ,          4       V P                  P                  V P                  4       V P                  P)                  V P*                  4       \        4       V n        V P,                  P                  V P                  4       V P,                  P	                  V P
                  4       V P,                  P                  V P                  RR 4       V P,                  P                  V P                  4       V P,                  P!                  V P,                  P#                  4       \$        P&                  ,          4       V P,                  P                  V P                  4       V P,                  P)                  V P*                  4       R# )a  Generate the conversation specific user Credentials.

Each Conversation has an associated user account used to simulate
any non Administrative user traffic.

Generates user credentials with good and bad passwords and ldap
simple bind credentials with good and bad passwords.
N)r   
user_credsguessr   set_workstationr2  set_passwordr5  set_usernamer4  
set_domainr   set_kerberos_stater   user_creds_badsimple_bind_credsset_gensec_featuresget_gensec_featuresr   FEATURE_SEALset_bind_dnr:  simple_bind_creds_badr   s   &r;   r<  !ReplayContext.generate_user_creds1  s    &-dgg&''(9(9:$$T]]3$$T]]3""4;;/**4+>+>?)m!!$''*++D,=,=>((s);<((7..t/B/BC "-$$TWW-..t/@/@A++DMM:++DMM:22""6686;N;NN	P11$2E2EF**4<<8%0]"""((1""2243D3DE""//cr0BC""//>""66&&::< 	! 	""55d6I6IJ""..t||<r=   c                   \        4       V n        V P                  P                  V P                  4       V P                  P	                  V P
                  4       V P                  P                  \        4       V P                  P                  V P                  4       V P                  P                  V P
                  R,           4       V P                  P                  V P                  4       V P                  P                  V P                  4       \        4       V n        V P                  P                  V P                  4       V P                  P	                  V P
                  4       V P                  P                  \        4       V P                  P                  V P                  RR 4       V P                  P                  V P
                  R,           4       V P                  P                  V P                  4       R# )zGenerate the conversation specific machine Credentials.

Each Conversation has an associated machine account.

Generates machine credentials with good and bad passwords.
$NrI  )r   machine_credsrK  r   rL  r2  set_secure_channel_typer   rM  r3  rN  rO  r   rP  r   machine_creds_badr   s   &r;   r;  $ReplayContext.generate_machine_creds_  si    )]  )**4+<+<=22<@''(8(89''(9(9C(?@%%dkk2--d.A.AB!,$$TWW-..t/@/@A66|D++D,<,<Sb,AB++D,=,=,CD11$2E2EFr=   c                @   V P                   P                  V4      pV'       d   \        P                  ! V4      # VP	                  4       pV'       dC   WP
                  9   d(   \        P                  ! V P
                  V,          4      # VR ,          pKJ  V P                  # ):   NN)r  r   r!  choicer  r  r   )rj   r  
attributes	attr_clues   &&& r;   get_matching_dnReplayContext.get_matching_dnx  so     ++//
;	==++--/++%}}T[[%9::bkG||r=   c                    R pV P                   '       d   V'       g   V P                   R,          # \        RV P                  ,          V^3V P                  4      pV P                   P	                  V4       V# )z$12345678-1234-abcd-ef00-01234567cffbzncacn_ip_tcp:%s)r,  r   r   r   r  )rj   newguidcs   &&  r;   get_dcerpc_connection#ReplayContext.get_dcerpc_connection  sb    5"""3**2...<"AY1&&q)r=   c                  a  S P                   '       d   V'       g   S P                   R,          # V 3R lpS P                  VS P                  S P                  S P                  4      w  pS n        S P                   P                  V4       V# )   c                 j   < \         P                   ! R SP                  ,          SP                  V 4      # zncacn_np:%s)r   r   r   r   rj   s   &r;   connect4ReplayContext.get_srvsvc_connection.<locals>.connect  s)    ==$++!>!%!&( (r=   rg  )r0  rF  rJ  rQ  r   r  rj   rh  rr  rj  s   f&  r;   get_srvsvc_connection#ReplayContext.get_srvsvc_connection  sz    """3**2..	( ,,W-1__-1-@-@-1-A-AC 	"D  	&&q)r=   c                  a  S P                   '       d   V'       g   S P                   R,          # V 3R lpS P                  VS P                  S P                  S P                  4      w  pS n        S P                   P                  V4       V# )rn  c                 r   < R p\         P                  ! RSP                  : RV: R2SP                  V 4      # )zschannel,seal,signncacn_ip_tcp:[]r   lsarpcr   r   )r   binding_optionsrj   s   & r;   rr  4ReplayContext.get_lsarpc_connection.<locals>.connect  s1    2O::#{{O="gg#% %r=   rg  )r-  rF  r[  r]  r   r  rt  s   f&  r;   get_lsarpc_connection#ReplayContext.get_lsarpc_connection  s|    """3**2..	% ,,W-1-?-?-1-C-C-1-A-AC 	"D  	&&q)r=   c                  a  S P                   '       d   V'       g   S P                   R,          # V 3R lpS P                  VS P                  S P                  S P                  4      w  pS n        S P                   P                  V4       V# )rn  c                 j   < \         P                  ! R SP                  ,          SP                  V 4      # rp  r|  rq  s   &r;   rr  ?ReplayContext.get_lsarpc_named_pipe_connection.<locals>.connect  s)    ::mt{{;"gg#% %r=   rg  )r.  rF  r[  r]  r   r  rt  s   f&  r;    get_lsarpc_named_pipe_connection.ReplayContext.get_lsarpc_named_pipe_connection  s|    (((0044	% ,,W-1-?-?-1-C-C-1-G-GI 	(D& 	%%,,Q/r=   c                <  a  S P                   '       d   V'       g   S P                   R,          pV# V 3R lpS P                  VS P                  S P                  S P                  4      w  pS n        \        V4      w  rgWV3pS P                   P                  V4       V# )zget a (drs, drs_handle) tuplec                 v   < R pRSP                   : RV: R2p\        P                  ! VSP                  V 4      # )sealry  rz  r{  )r   r   r   )r   r~  binding_stringrj   s   &  r;   rr  :ReplayContext.get_drsuapi_connection_pair.<locals>.connect  s/    $O"kk?<N??>477EBBr=   rg  )r/  rF  rJ  rQ  r   r   r  )rj   rh  unbindrj  rr  drs
drs_handlesupported_extensionss   f&&     r;   get_drsuapi_connection_pair)ReplayContext.get_drsuapi_connection_pair  s    ###C((,AH	C ,,W-1__-1-@-@-1-B-BD 	%d# .8_*  ''*r=   c                  a  S P                   '       d   V'       g   S P                   R,          # V 3R lpV 3R lpV'       d<   S P                  VS P                  S P                  S P                  4      w  pS n        M:S P                  VS P
                  S P                  S P                  4      w  pS n        S P                   P                  V4       V# )rn  c                V   < \        RSP                  ,          V SP                  R7      # )z
To run simple bind against Windows, we need to run
following commands in PowerShell:

    Install-windowsfeature ADCS-Cert-Authority
    Install-AdcsCertificationAuthority -CAType EnterpriseRootCA
    Restart-Computer

z
ldaps://%sr   r   r   r   r   rq  s   &r;   simple_bind6ReplayContext.get_ldap_connection.<locals>.simple_bind  s'     3%* GG% %r=   c                 V   < \        R SP                  ,          V SP                  R7      # )r   r  r  rq  s   &r;   	sasl_bind4ReplayContext.get_ldap_connection.<locals>.sasl_bind  s%    t{{2%* GG% %r=   rg  )	r+  rF  rR  rW  r   rJ  rQ  r   r  )rj   rh  simpler  r  samdbs   f&&   r;   get_ldap_connection!ReplayContext.get_ldap_connection  s       ((,,	%	% 00151G1G151K1K151J1JL /UD- 0015151D1D151C1CE (UD& 	$$U+r=   c                    V P                   '       d	   V'       dF   V P                   P                  \        V P                  V P                  V P
                  R 7      4       V P                   R,          # ))r   r   rg  )r1  r  SamrContextr   r   r   )rj   rh  s   &&r;   get_samr_contextReplayContext.get_samr_context  sN    !!!S%%DKKDGG4::FH!!"%%r=   c                   a  S P                   '       d   S P                   # V 3R  lpS P                  VS P                  S P                  S P                  4      w  pS n        VS n         V# )c                 j   < \         P                   ! R SP                  ,          SP                  V 4      # )zncacn_ip_tcp:%s[schannel,seal])r   r   r   rq  s   &r;   rr  6ReplayContext.get_netlogon_connection.<locals>.connect  s/    $$%E&*kk&3%)WW%*, ,r=   )r   rF  r[  r]  r   )rj   rr  rj  s   f  r;   get_netlogon_connection%ReplayContext.get_netlogon_connection  si    ###+++	, ,,W-1-?-?-1-C-C-1-C-CE 	$D"
 $% r=   c                    V P                   R 3# )Ar   r   s   &r;   guess_a_dns_lookup ReplayContext.guess_a_dns_lookup$  s    

C  r=   c                    V P                   P                  4       p\        4       p\        VR ,          4      VP                  n        VR,          Vn        \        4       pW#3# )
credentialr`   )r[  new_client_authenticatorr   r  creddatar`   )rj   authcurrent
subsequents   &   r;   get_authenticatorReplayContext.get_authenticator'  sR    !!::<%' l!34 -')
$$r=   c                    \         P                  P                  V P                  V4      p\	        VR4      pVP                  4        F  w  rE\        V: RV: 2VR7       K  	  VP                  4        R# )zWrite arbitrary key/value pairs to a file in our stats directory in
order for them to be picked up later by another process working out
statistics.wz: r1   N)ospathr|   r   openitemsr4   close)rj   filenamekwargsrA  r  vs   &&,   r;   write_statsReplayContext.write_stats0  sR     77<<x83LLNDAa#!, #		r=   )/r  r   r   r   r,  r  r   r   r/  r   r   r   r   r   r   r   r   r   r   r   r+  r   r-  r.  r[  r]  r3  r2  r   r   r   r8  r9  r1  r  r   rR  rW  r0  r   r   r   rJ  rQ  r:  r4  r5  r^   )F)FF)rV   rW   rX   rY   r   r  environr   rk   r   r&  r>  rF  r<  r;  rd  rk  ru  r  r  r  r  r  r  r  r  r  rZ   r   r   s   @r;   r   r   Z  s      %)'+!%

x0 !*+XPFn!$#>*8,=\G2,$($.$L&$!% r=   r   c                   :   a  ] tR tRt o RtRR ltR tR tRtV t	R# )	r  i;  z5State/Context associated with a samr connection.
    Nc                    R V n         R V n        R V n        R V n        R V n        R V n        R V n        Wn        W n        W0n	        R # r^   )

connectionhandledomain_handler   group_handleuser_handleridsr   r   r   )rj   r   r   r   s   &&&&r;   rk   SamrContext.__init__>  sE    !!!!!!!	#"
r=   c                    V P                   '       gD   \        P                  ! R V P                  ,          V P                  V P                  R7      V n         V P                   # )zncacn_ip_tcp:%s[seal])lp_ctxr   )r  r   r   r   r   r   s   &r;   get_connectionSamrContext.get_connectionJ  sA    "ii'4;;7ww JJ(DO
 r=   c                    V P                   '       g6   V P                  4       pVP                  R \        P                  4      V n         V P                   # r^   )r  r  Connect2r   SEC_FLAG_MAXIMUM_ALLOWED)rj   rj  s   & r;   
get_handleSamrContext.get_handleS  s;    {{{##%A**T8+L+LMDK{{r=   )
r  r   r  r   r  r  r   r  r   r  NN)
rV   rW   rX   rY   r   rk   r  r  rZ   r   r   s   @r;   r  r  ;  s     
# r=   r  c                      a  ] tR tRt o RtRR ltR tR tRR ltR t	]	t
R	 tR
 tR tR tRR ltRR ltR tR tRtV tR# )ConversationiZ  zADetails of a converation between a simulated client and a server.Nc                    Wn         W n        . V n        \        V4      V n        R V n        W@n        V F  pV P                  ! V!   K  	  R# r   N)
start_timeri   packetsrS   r9   client_balancer   add_short_packet)rj   r  ri   seqr   rL   s   &&&&& r;   rk   Conversation.__init__\  sE    $"&y1!.A!!1% r=   c                    V P                   f   VP                   f   ^ # R# VP                   f   ^# V P                   VP                   ,
          # )Nrg  )r  r   s   &&r;   r   Conversation.__cmp__g  sD    ??"'I#!1!111r=   c                   VP                  4       pV P                  f   VP                  V n        V P                  f   VP                  V n        VP                  V P                  8w  d(   \	        RV P                  : RVP                  : 24      hV;P                  V P                  ,          un        VP
                  VP                  ^ ,          8X  d)   V ;P                  VP                  4       ,          un        M'V ;P                  VP                  4       ,          un        VP                  4       '       d   V P                  P                  V4       R# R# )zeAdd a packet object to this conversation, making a local copy with
a conversation-relative timestamp.NzConversation endpoints z don't matchpacket endpoints )r   r  r`   ri   rU   rc   r  r   r   r  r  )rj   packetrL   s   && r;   
add_packetConversation.add_packetp  s     KKM??"kkDO>>![[DN;;$..(!#'>>1;;#@ A A 	
t&55AKKN"1>>#331>>#33!!LL" "r=   c                Z   V'       d   \        W#4      '       g   R# V P                  4       w  rxV'       g   YrW#3p	\        P                  V	R4      p
\        P                  VR4      p\        WP                  ,
          VRWxW#W4	      pVP                  VP                  ^ ,          8X  d)   V ;P                  VP                  4       ,          un	        M'V ;P                  VP                  4       ,          un	        VP                  4       '       d   V P                  P                  V4       R# R# )zCreate a packet from a timestamp, and 'protocol:opcode' pair, and a
(possibly empty) list of extra data. If client is True, assume
this packet is from the client to the server.
Nr{   06)r   guess_client_serverOP_DESCRIPTIONSr   IP_PROTOCOLSr\   r  rc   ri   r  r   r   r  r  )rj   r`   re   rf   rh   clientskip_unused_packetsrc   rd   r   rg   ra   r  s   &&&&&&&      r;   r  Conversation.add_short_packet  s     '7'I'I,,.	 ""3+"&&x6	OO3[C $7 ::))!,,6#6#6#886#6#6#88$$&&LL' 'r=   c                ~    R V P                   V P                  V P                  \        V P                  4      3,          # )z-<Conversation %s %s starting %.3f %d packets>)r   ri   r  lenr  r   s   &r;   r   Conversation.__str__  s5    ?%%t~~tT\\"$$ 	%r=   c                ,    \        V P                  4      # r^   )iterr  r   s   &r;   __iter__Conversation.__iter__  s    DLL!!r=   c                ,    \        V P                  4      # r^   )r  r  r   s   &r;   __len__Conversation.__len__  s    4<<  r=   c                    \        V P                  4      ^8  d   ^ # V P                  R,          P                  V P                  ^ ,          P                  ,
          # )r   rg  )r  r  r`   r   s   &r;   get_durationConversation.get_duration  s>    t||q ||B))DLLO,E,EEEr=   c                t    V P                    Uu. uF  qP                  V P                  4      NK  	  up# u upi r^   )r  r   r  )rj   rL   s   & r;   replay_as_summary_lines$Conversation.replay_as_summary_lines  s)    7;||D|!T__-|DDDs   #5c                
   V P                   p\        P                  ! 4       V,
          pWE,
          pV\        ,
          pV^ 8  d   \        P                  ! V4       \        P                  ! 4       V,
          V,
          pV P	                  RW3,          4       Rp	Rp
\        P                  ! 4       pV P
                   F  p\        P                  ! 4       V,
          pW\P                  ,
          pWi8  d   Tp	V^ 8  dq   V) \        ,
          pV^ 8  d\   \        P                  ! V4       \        P                  ! 4       V,
          pWLP                  ,
          V
8  d   WLP                  ,
          p
VP                  W4       K  	  WV
3# )zEReplay the conversation at the right time.
(We're already in a fork).zstarting %s [miss %.3f]r   )r  r   SLEEP_OVERHEADsleepr9   r  r`   r   )rj   r   r   r=  r~   nowgap
sleep_timemissmax_gapmax_sleep_missp_startrL   s   &&&&         r;   replay_with_delayConversation.replay_with_delay  s    OOiikE!g>)
>JJz"		e#q(*d\9:))+A))+'C#C}Qw!TN2
>JJz*		g-A;;7)*[[FF4!  n,,r=   c                    V P                   w  r#V P                  ^ 8  d   W#3# V P                  ^ 8X  d
   W8X  d   W#3# W23# )zXHave a go at deciding who is the server and who is the client.
returns (client, server)
)ri   r  )rj   server_cluerF   bs   &&  r;   r   Conversation.guess_client_server  sG     ~~"6M
 !#(86Mvr=   c                   V P                    Uu. uF#  q1VP                  u;8:  d
   V8:  g   K  M K!  VNK%  	  upV n         V P                   '       d%   V P                   ^ ,          P                  V n        R# RV n        R# u upi )zyPrune any packets outside the time window we're interested in

:param s: start of the window
:param e: end of the window
Nr  r`   r  )rj   rQ   r   rL   s   &&& r;   forget_packets_outside_window*Conversation.forget_packets_outside_window  sZ     $(<<I<a3Hq3H3H<I7;|||$,,q/33 Js   A?A?A?c                    V P                    F  pV;P                  V,          un        K  	  V P                  e   V ;P                  V,          un        R# R# )z=Adjust the packet start times relative to the new start time.Nr  )rj   r  rL   s   && r;   renormalise_timesConversation.renormalise_times  s=    AKK:%K  ??&OOz)O 'r=   )r  r   ri   r9   r  r  )NNrO   N)TTr  r^   )rV   rW   rX   rY   r   rk   r   r  r  r   r   r  r  r  r  r	  r  r  r  rZ   r   r   s   @r;   r  r  Z  sY     K	&2#4(8%
 H"!F
E!-F"N* *r=   r  c                   H   a  ] tR tRt o RtR	R ltR tR	R ltR	R ltRt	V t
R# )
	DnsHammeri  zKA lightweight conversation that generates a lot of dns:0 packets on
the flyNc                $   \        W,          4      p\        V4       Uu. uF  p\        P                  ! ^ V4      NK  	  upV n        V P                  P                  4        Wn        W n        ^ V n        V P                  VR7      V n
        R# u upi )r   
query_fileN)rt   r  r!  uniformtimessortrater   r  _get_query_choicesquery_choices)rj   dns_rater   r  nr  s   &&&&  r;   rk   DnsHammer.__init__  so    #$;@8D8afnnQ18D


	 !44
4K Es    Bc                h    R \        V P                  4      V P                  V P                  3,          # )z-<DnsHammer %d packets over %.1fs (rate %.2f)>)r  r  r   r  r   s   &r;   r   DnsHammer.__str__  s)    ?TZZ$--;< 	=r=   c                   V'       d   \        VR4      ;_uu_ 4       pVP                  4       pRRR4       . pXP                  4        Fj  pVP                  4       pV'       g   K  VP	                  R4      '       d   K6  VP                  R4      p\        V4      ^8X  g   Q hVP                  V4       Kl  	  V# . RO#   + '       g   i     L; i)z
Read dns query choices from a file, or return default

rname may contain format string like `{realm}`
realm can be fetched from context.realm
r  N#r   )
)r   {realm}r  yes)rn  r(  NSr)  )r   	*.{realm}r  no)r`  r+  r*  r,  )
   _msdcs.{realm}r  r)  )   r.  r*  r)  )   nx.realm.comr  r,  )   r1  r*  r,  )   *.nx.realm.comr  r,  )   r4  r*  r,  )r  read
splitlinesstripr  rr   r  r  )rj   r  rA  textchoicesrv   r:   s   &&     r;   r  DnsHammer._get_query_choices  s     j#&&!vvx 'G)zz|4 4 4::c?Dt9>)>NN4( * N  '&s   B<<C	c           
        V'       g   Q hVP                   '       g   Q h\        P                  ! 4       pV P                   F  p\        P                  ! 4       V,
          pW4,
          pV\        ,
          pV^ 8  d   \        P                  ! V4       \
        P                  ! V P                  4      w  rxrVP                  VP                   R7      pRp\        P                  ! 4       p \        W4      pV
R8X  d   \        V4      '       g   Rp\        P                  ! 4       pY,
          p\        RYY3,          4       EK  	  R#   \         d    Rp LGi ; i  \        P                  ! 4       pY,
          p\        RYY3,          4       i ; i)r   r  Tr)  Fz%f	DNS	dns	%s	%f	%s	N)r   r   r  r   r  r!  ra  r   r   	dns_queryr  r   r4   )rj   r   r   r~   r  r  r  rf   rnamertypeexistsuccesspacket_startanswersrA   r   s   &&              r;   replayDnsHammer.replay3  s,   w}}}}		A))+%C'C~-JA~

:&*0--8J8J*K'F5LLw}}L5EG99;L
W#E1E>#g,,#G iik-2c85UUV+       iik-2c85UUVs$   (%EEEEE3F)r   r   r  r  r  r^   )rV   rW   rX   rY   r   rk   r   r  rD  rZ   r   r   s   @r;   r  r    s'     L=BW Wr=   r  c                $   \        \        4      p. pV  F  p\        V\        4      '       d   \	        V4      p\        RVP                  : 2\        P                  R7       V Fa  p\        P                  V4      pVP                  R8X  d(   VR8w  d!   W&P                  ;;,          ^,          uu&   KP  VP                  V4       Kc  	  VP                  4        K  	  V'       g   . ^ 3# \        R V 4       4      p\!        R V 4       4      p\        R\        P                  R7       \#        4       p	\%        V4       Fo  w  rV;P&                  V,          un        V	P)                  VP*                  4      pVf"   \-        V
^,           R7      pWVP*                  &   VP/                  V4       Kq  	  . pV	P1                  4        F&  p\3        V4      ^ 8w  g   K  VP                  V4       K(  	  \5        W,
          4      p\3        V	4      V,          pWW3# )	zLLoad a summary traffic summary file and generated Converations from it.
    z
Ingesting r1   r$   includec              3   8   "   T F  qP                   x  K  	  R # 5ir^   r   r   rL   s   & r;   r   #ingest_summaries.<locals>.<genexpr>e  s     2'Q[['   c              3   8   "   T F  qP                   x  K  	  R # 5ir^   r   rI  s   & r;   r   rJ  f  s     37akk7rK  z$gathering packets into conversations)r   )r   rt   
isinstancer
  r  r4   r/   r5   r6   r\   rx   re   rf   r  r  minmaxr   	enumerater`   r   ri   r  r  valuesr  rs   )filesdns_mode
dns_countsr  rA  rv   rL   r  last_packetconversationsr  rj  conversation_listr   mean_intervals   &&             r;   ingest_summariesrY  O  s    S!JGaQA(szz:D  &AzzU"x9'<88$)$q!  	
	  1u2'22J3733K	
0szzBMM'"	z!akk*9a!e5A)*!++&	Q # !!#q6Q;$$Q' $ [-.H&1MXAAr=   c                     \        4       pV  F  pVP                  VP                  4       K   	  V'       d   VP                  ^4      ^ ,          # R# rn  N)r   updateri   most_common)rV  	addressesrj  s   &  r;   guess_server_addressr_    sC    	I% $$Q'** r=   c                 f    / pV P                  4        F  w  r#R P                  V4      pW1V&   K  	  V# ro   )r  r|   )rR   yr  r  k2s   &    r;   stringify_keysrd    s4    
A	YYq\"  Hr=   c                     / pV P                  4        F,  w  r#\        \        V4      P                  R 4      4      pW1V&   K.  	  V# ra  )r  r7   r
  rr   )rR   rb  r  r  r~   s   &    r;   unstringify_keysrf    s>    
A	#a&,,t$%!  Hr=   c                   `   a  ] tR tRt o RR ltRR ltR tR tRR ltR t	R	 t
RR
 ltRtV tR# )TrafficModeli  c                v    / V n         / V n        Wn        \        \        4      V n        R V n        ^ ^.V n        R# r  )ngramsquery_detailsr"  r   rt   dns_opcountscumulative_durationpacket_rate)rj   r"  s   &&r;   rk   TrafficModel.__init__  s7    ',#& q6r=   Nc           
        Vf   / pRpRp\         3V P                  ^,
          ,          p\        V4      pVP                  4        F$  w  rxV P                  V;;,          V,          uu&   K&  	  \        V4      ^8  d   V^ ,          P                  p	^ p
V	R,           pV F;  pV
\        V4      ,          p
\        WP                  R,          P                  4      pK=  	  WP                  ^ &   W,
          V P                  ^&   V EF  pVP                  V4      w  rWLP                  4       ,          p\         3V P                  ^,
          ,          pV EF9  pVP                  V8w  d   K  VP                  V,
          pVP                  pV\        8  do   R\        P                   ! \        RV\"        ,          4      4      ,          pV P$                  P'                  V. 4      P)                  V4       VR,          V3,           pVP+                  4       pV P,                  P'                  V. 4      P)                  \/        VP0                  4      4       V P$                  P'                  V. 4      P)                  V4       VR,          V3,           pEK<  	  EK  	  V ;P2                  V,          un        V P$                  P'                  V. 4      P)                  \         4       R # )Nr   g?wait:%dr%   rn  NNrg  )
NON_PACKETr"  r_  r  rl  r  r  rO  r  r`   rn  r  r  rc   WAIT_THRESHOLDmathlog
WAIT_SCALErj  r  r  r   rk  r7   rh   rm  )rj   rV  rl  prevcum_durationr   r   r  r  firsttotallastrj  r  rL   elapsedr   short_ps   &&&               r;   learnTrafficModel.learn  sF   Lmtvvz*%m4 &&(DAa A%  ) }!!!$//EE3;D"Q42!8!89 # #(Q"&,DQA226:NFNN,,L-466A:.C55F?++,{{^+$S5<z5I2K )L MDKK**33::4@b'TG+C**,""--g.0228&qww2H&&sB/66w?"g
*# 	 . 	  L0 sB'..z:r=   c           
        / pV P                   P                  4        F,  w  r4R P                  V4      p\        \	        V4      4      W#&   K.  	  / pV P
                  P                  4        F"  w  r4\        \	        R V 4       4      4      WS&   K$  	  RVRVRV P                  RV P                  R\        /pV P                  VR&   \        V\        4      '       d   \        VR4      p\        P                  ! Wa^R	7       R
# )ro   c              3   X   "   T F   pV'       d   R P                  V4      MRx  K"  	  R# 5i)ro   r#   N)r|   r   s   & r;   r   $TrafficModel.save.<locals>.<genexpr>  s&      ,856 =>DIIaL3,F56s   **rj  rk  rm  rn  versionr$   r  )indentN)rj  r  r|   dictr   rk  rm  rn  CURRENT_MODEL_VERSIONrl  rM  r
  r  jsondump)rj   rA  rj  r  r  rk  ds   &&     r;   saveTrafficModel.save  s    KK%%'DA		!AWQZ(FI ( &&,,.DA#G ,856,8 %8  9M /
 f]!4#;#;4++,
 $$%aQA		!q!r=   c           	        \        V\        4      '       d   \        V4      p\        P                  ! V4      p VR ,          pV\
        8  d   \        RV\
        3,          4      h TR,          P                  4        F  w  rE\        \        T4      P                  R4      4      pT P                  P                  T. 4      pTP                  4        F'  w  rxTP                  \        T4      .T,          4       K)  	  TP                  4        K  	  TR,          P                  4        F  w  rET P                  P                  \        T4      . 4      pTP                  4        Fa  w  rxTR8X  d   TP                  R.T,          4       K'  TP                  \        \        T4      P                  R4      4      .T,          4       Kc  	  TP                  4        K  	  RT9   d@   TR,          P                  4        F$  w  rET P                   T;;,          T,          uu&   K&  	  TR,          T n        TR	,          T n        R
#   \         d    \        R\
        ,          4      hi ; i)r  z4the model file is version %d; version %d is requiredz=the model file lacks a version number; version %d is requiredrj  ro   rk  r#   r$   rm  rn  NrO   )rM  r
  r  r  loadREQUIRED_MODEL_VERSION
ValueErrorKeyErrorr  r7   rr   rj  r  extendr  rk  rl  rm  rn  )	rj   rA  r  r  r  r  rQ  rL   counts	   &&       r;   r  TrafficModel.load  s   aQAIIaL		;	lG//  ":")+A!B"C D D 0 hK%%'DAc!fll4()A[[++Ar2FGGIs1vh./ &KKM ( o&,,.DA''223q62>FGGI8MM2$,/MM5Qd);#<"="EF	 &
 KKM / A:%(!!!$)$ ) $%%:#; ]+5  	;  ":"8": ; ;	;s   ,H> >"I c                   . p\         3V P                  ^,
          ,          pVf
   V^,
          p \        P                  ! V P                  P                  V\         34      4      pV\         8X  d   W8  d    V# \        P                  ! 4       V8  d'   \        RWu3,          \        P                  R7        V# R\        P                  ! ^^4      ,          p\        RV,          \        P                  R7       WP                  9   d)   \        P                  ! V P                  V,          4      p	M. p	VP                  R^4      w  rV
R8X  dW   \        V4      \        P                  ! 4       ,           p\        P                  ! V4      \        V,          ,          pW,          pMb\        P                   ! \#         p\        P                  ! V4      V,          pW,          pVe
   W8  d    V# W8  d   VP%                  WW34       VR,          V3,           pVR
,          R,          R	8X  g   EK   VR,          R,          R	8X  g   EK  \         3V P                  ^,
          ,          pEK:  )zEConstruct an individual conversation packet sequence from the
model.
z"ending after %s (persistence %.1f)r1   rq  ztrying %s instead of endr   r   rr  :N   Nzwait:rg  )rs  r"  r!  ra  rj  r   r4   r5   r6   	randrangerk  rr   rt   ru  exprw  r  NO_WAIT_LOG_TIME_RANGEr  )rj   r`   	hard_stopreplay_speedignore_beforepersistencerj  r   rL   rh   re   rf   log_wait_timer   log_waits   &&&&&&         r;   construct_conversation_sequence,TrafficModel.construct_conversation_sequence  s    mtvvz* %MMdkkoocJ=ABAJ,F E ==?[0>#ASS"zz+> ;  0 0B 770143::F&&&d&8&8&;< wwsAH6! #Ffmmo =xx.*|2KL!	!>>+ABxx)L8!	(Y-B  -HHi6ABb'QD.C2wr{g%#b'"+*@ "mtvvz2r=   c                <    V P                   w  r#W,          V,          # r^   rn  )rj   scalerate_nrate_ts   &&  r;   scale_to_packet_rate!TrafficModel.scale_to_packet_rateO  s    **~&&r=   c                <    V P                   w  r#W,          V,          # r^   r  )rj   ppsr  r  s   &&  r;   packet_rate_to_scale!TrafficModel.packet_rate_to_scaleS  s    **v%%r=   c                   ^	V,          p\        W,          4      p. p^ pW8  du   \        P                  ! V) V4      p	V P                  V	VV^ VR7      p
V
 F  w  rr\	        W4      '       g   K   M	  KU  VP                  V
4       V\        V
4      ,          pKz  V P                  V4      p\        RW\        V4      W3,          \        P                  R7       VP                  4        V# )z<Generate a list of conversation descriptions from the model.)r  r  r  r  zGwe have %d packets (target %d) in %d conversations at %.1f/s (scale %f)r1   )rt   r!  r  r  r   r  r  r  r4   r5   r6   r  )rj   rn  r   r  r  lead_intarget_packetsrV  	n_packetsr   rj  r`   re   rf   rh   r  s   &&&&&           r;   generate_conversation_sequences,TrafficModel.generate_conversation_sequencesW  s     h,[34	(NNG8X6E44U?GBNCDAL	 5 NA 782	V1(CC 78   #QI))+6 (#m:L*33 ::	 	r=   )rm  rl  r"  rj  rn  rk  )r`  r^   )r   Nrn  r   r   )rn  r   )rV   rW   rX   rY   rk   r  r  r  r  r  r  r  rZ   r   r   s   @r;   rh  rh    s5     "0;d"2&,P4l'&% %r=   rh  c                     . pV  FC  pV'       g   K  \        V^ ,          ^ ,          W3V4      pV^,          pVP                  V4       KE  	  V# )r   )r  r  )r  r   r  rV  rQ   rj  s   &&&   r;   seq_to_conversationsr    sN    M1QqT!Wv&6:AaKF  #	 
 r=   rpc_netlogonr  r   r}  r   epmr   r   zHost Announcement (0x01)zRequest Announcement (0x02)zBrowser Election Request (0x08)zGet Backup List Request (0x09)z$Domain/Workgroup Announcement (0x0c)z Local Master Announcement (0x0f)searchRequestsearchResDoneRequestBindBind_ackBind_nakAlter_contextAlter_context_respAUTH3Responser	   responseDsBindDsCrackNamesDsWriteAccountSpnDsUnbindDsReplicaSyncDsGetNCChangesDsReplicaUpdateRefsMapr{   bindRequestbindResponseunbindRequestsearchResEntryz*** Unknown ***lsa_LookupNameslsa_LookupSidslsa_QueryTrustedDomainInfoBySidlsa_SetTrustedDomainInfolsa_OpenPolicylsa_LookupSids3lsa_LookupNames4NetrLogonDummyRoutine1NetrServerAuthenticate3NetrLogonGetDomainInfoNetrServerPasswordSet2NetrLogonSamLogonExDsrEnumerateDomainTrustsNetrLogonSamLogonWithFlagsNetrServerReqChallengeConnectGetAliasMembershipLookupNames
LookupRids	OpenGroupCloseQueryGroupMemberOpenUserQueryUserInfoGetGroupsForUserQuerySecurityLookupDomainConnect5EnumDomains
OpenDomainQueryDomainInfozClose (0x04)zLocking AndX (0x24)zRead AndX (0x2e)zTrans2 (0x32)zTree Disconnect (0x71)zNegotiate Protocol (0x72)zSession Setup AndX (0x73)zLogoff AndX (0x74)zTree Connect AndX (0x75)zNT Create AndX (0xa2)NegotiateProtocolIoctlFindGetInfoBreakSessionSetupSessionLogoffTreeConnectTreeDisconnectCreateReadz$SAM LOGON request from client (0x12)z3SAM Active Directory Response - user unknown (0x17)NetShareGetInfoNetSrvGetInfoc                     V P                  R ^4      w  rV\        P                  WV3R4      p\        P                  VR4      pWRW#WVV.p	V	P	                  V4       RP                  V	4      # )r   r{   r  ro   )rr   r  r   r  r  r|   )
rL   r`   rc   rd   rh   re   rf   rg   ra   rv   s
   &&&&&     r;   expand_short_packetr    se    wwsAH126D""8T2KB8TJDKK99T?r=   c                    \         P                  P                  4        \         P                  P                  4        \        P
                  ! ^ 4       R# )zSignal handler closes standard out and error.

Triggered by a sigterm, ensures that the log messages are flushed
to disk and not lost.
N)r5   r6   r  stdoutr  _exit)signalframes   &&r;   flushing_signal_handlerr    s/     JJJJHHQKr=   c                l   VR,          \         P                  ! ^ R4      ,           p\        P                  P	                  4        \        P
                  P	                  4        \        P                  ! 4       pV^ 8w  d   V#  \         P                  ! V4       WT3p^ p	V ^ ,          ^ ,          p
\        WWR7      p\        P                  ! \        P                  \        4       VP                  W;4       \        P                  P                  4        \        P                  ! ^ 4       \        P                   P#                  VP$                  RVP&                  ,          4      p\)        VR4      p \        P                  P                  4        \        P                  ! ^4       V\        n        \0        P0                  ! 4       V,
          pW,
          pV\2        ,
          pV^ 8  d   \0        P4                  ! V4       VP7                  VVR7      w  ppp\9        R	V,          4       \9        R
V,          4       \9        RV,          4       \        P
                  P                  4        \        P                  P                  4        \        PB                  ! V	4       R#   \*         d(   p\,        P/                  RT,          4        Rp?EL'Rp?ii ; i  \:         d    ^p	\9        R\        P<                  ! 4       X3,          \        P
                  R7       \>        P@                  ! \        P
                  4       \        P
                  P	                  4         ELi ; i  \        P
                  P                  4        \        P                  P                  4        \        PB                  ! X	4       i ; i)z8Fork a new process and replay the conversation sequence.  i  )r  r   zstats-conversation-%dr  stdout closing failed with %sN)r   r   zMaximum lag: %fzStart lag: %fzMax sleep miss: %fz*EXCEPTION in child PID %d, conversation %sr1   )"r!  randintr5   r  rD   r6   r  forkseedr  r   SIGTERMr  r>  stdinr  r  r|   r   r   r  IOErrorr   infor   r   r  r	  r4   r   getpidrB   	print_excr  )csr   r   r=  	client_id	server_idr  pidri   statusr~   rj  r  rA  r   r  r  r  max_lag	start_lagr  s   &&&&&&               r;   replay_seq_in_forkr    s    tfnnQ44D JJJJ
'')C
ax

*D*	qE!H2Ifnn&=>--g9		
77<< 0 02I ! 1 132 33	=JJHHQK 
iikE!g>)
>JJz"-.-@-@uIP .A .R*N')*o	)*"^34 	




3  	=KK7!;<<	=   ;ryy{A>NN::	CJJ'

 	




sR   C-K /4J #B&K K(K
K 
KK BMM MM AN3c                 4   \         P                  P                  4        \         P                  P                  4        \        P
                  ! 4       pV^ 8w  d   V# \         P                  P                  4        \        P                  ! ^ 4        \         P                  P                  4        \        P                  ! ^4       \        P                  P                  VP                  R4      p\        VR4      \         n         ^ p\        P                  ! \        P                   \"        4       \%        WVR7      pVP'                  VR7       \         P                  P                  4        \         P                  P                  4        \        P2                  ! V4       R#   \         d(   p\        P                  RT,          4        Rp?ELRp?ii ; i  \(         d_    ^p\+        R\        P,                  ! 4       ,          \         P                  R7       \.        P0                  ! \         P                  4        Li ; i  \         P                  P                  4        \         P                  P                  4        \        P2                  ! X4       i ; i)	r   r  Nz	stats-dnsr  r  )r   z)EXCEPTION in child PID %d, the DNS hammerr1   )r5   r  rD   r6   r  r  r
  r  r  r   warnr  r|   r   r  r   r	  r  r  rD  r   r4   r  rB   r  r  )	r!  r   r   r  r  r   r  r  hammers	   &&&&     r;   dnshammer_in_forkr  R  s   JJJJ
'')C
ax
IIOOHHQK9


 ww||G,,k:Hh$CJfnn&=>8*Eg& 	




%  93a7889  (:biikJ::	CJJ'	( 	




s?   4F" A
G "G-GGA&I =I ?I  I AJc
                 ^   \        RR VRVRVR\        V 4      /V
B p\        V4      \        V 4      8  d'   \        R\        V4      \        V 4      3,          4      h\        P                  ! 4        \        V 4      R,          p\
        P
                  ! 4       V,           pVf   V R,          R,          ^ ,          V,           p\        RV,          \        P                  R7       \        R	W|,           ,          \        P                  R7       \        R
V,          \        P                  R7       W,           R,           p\        P                  R\        V 4      V3,          4       VP                  R\        V 4      \        R V  4       4      R7       / p V'       d   \        WWVVR7      p^VV&   \        V 4       F+  w  ppVV,          pV^,           p\        VWVV4      pVVV&   K-  	  \
        P
                  ! 4       p\        RVV,
          V,           VV,
          3,          \        P                  R7       \
        P
                  ! 4       V8  d   V'       d   \
        P                   ! R4        \        P"                  ! R\        P$                  4      w  ppT'       g   Kk  TP-                  TR4      p\.        ^ 8  d/   \        RTT\        T4      3,          \        P                  R7       T	'       g   K  T^ 8w  g   K   TP                  R\        T4      R7       R EF  p\        R\        T4      T3,          \        P                  R7       T F  p \        P6                  ! TT4       K  	  \
        P                   ! R4       \
        P
                  ! 4       ^,           pT'       d    \        P"                  ! R\        P$                  4      w  ppX^ 8w  d   TP-                  TR4      pTfe   \        RT,          4       \        P                  P;                  4        \        P<                  P;                  4        \        P>                  ! ^4       \        RTT\        T4      3,          \        P                  R7       \
        P
                  ! 4       T8  g   K   T'       g    M\
        P                   ! ^4       EK  	  T'       d,   \        R\        T4      ,          \        P                  R7        \        P@                  ! ^ ^4       R#   \&         d#   pTP(                  \*        8w  d   h  Rp?EK9  Rp?ii ; i  \0         d5    \        R\        P                  R7       \2        P4                  ! 4         ELi ; i  \&         d#   pTP(                  \8        8w  d   h  Rp?EKZ  Rp?ii ; i  \&         d"   pTP(                  \*        8w  d   h  Rp?ELRp?ii ; i  \B         d     \        R\        P                  R7        R# i ; i  TP                  R\        T4      R7       R EF  p\        R\        T4      T3,          \        P                  R7       T FJ  p \        P6                  ! TT4       K    \&         d"   pTP(                  \8        8w  d   h  Rp?KD  Rp?ii ; i	  \
        P                   ! R4       \
        P
                  ! 4       ^,           pT'       Ed&    \        P"                  ! R\        P$                  4      w  ppM.  \&         d!   pTP(                  \*        8w  d   h  Rp?MRp?ii ; iX^ 8w  d   TP-                  TR4      pTfe   \        RT,          4       \        P                  P;                  4        \        P<                  P;                  4        \        P>                  ! ^4       \        RTT\        T4      3,          \        P                  R7       \
        P
                  ! 4       T8  g   EK-   T'       g    M\
        P                   ! ^4       EK  	  T'       d,   \        R\        T4      ,          \        P                  R7        \        P@                  ! ^ ^4       i   \B         d    \        R\        P                  R7        i i ; i; i) r   r   r   r   z(we have %d accounts but %d conversationsg{Gz?NzWe will start in %.1f secondsr1   zWe will stop after %.1f secondszruntime %.1f secondsr%   z6Replaying traffic for %u conversations over %d seconds
intentionsc              3   8   "   T F  p\        V4      x  K  	  R # 5ir^   )r  r   s   & r;   r   replay.<locals>.<genexpr>  s     +M<LqCFF<LrK  )Planned_conversationsPlanned_packetsr  z,all forks done in %.1f seconds, waiting %.1fg~jth?z-process %d finished conversation %d; %d to gozEXCEPTION in parent
unfinished)Unfinished_conversationszkilling %d children with -%d      ?zchildren is %s, no pid foundz)kill -%d %d KILLED conversation; %d to goz%d children are missingzignoring fake ^CrO   rg  )   r$  	   )"r   r  r  r  setpgrpr   r4   r5   r6   r   r  r  sumr  rP  r  r  waitpidWNOHANGOSErrorerrnor   popr3   r   rB   r  killr   rD   r  r  killpgKeyboardInterrupt)conversation_seqhostr   r   accountsr!  dns_query_filer   latency_timeoutstop_on_any_errorr  r   delayr   rA   childrenr  r  r  r=  r  r~   r  r   rj  rQ   s   &&&&&&&&&&,               r;   rD  rD  t  s     &4 &"'&!& 144D0E& %	&G 8}s+,,Dx=#.>*?@A C 	C
 JJL  !D(EIIK%E $B'+A.@	
)E
1zz	
+x/?
@zz	
 8
+zz 
S
 C
KKH!"H-. / .12B.C(++M<L+M(M  O HY7#H/=?CHSM/0EArqkGAI$R)LC%HSM	 1 IIK<5y5 !e),-::	 iikCHJJu jjRZZ8V
 sLLd+? 'CM23:=**F %$1 	L58] 	 	D A1M1%&-0ZZ9GGCO   JJsO))+/C"$**R"<KC !8 S$/Ay<xGH

((*

((* &sCM23  #zz+ 99;#%JJqMC F +c(m;zz#	7IIaOC  77f$  ##**5  ww%' (  ww&( )@ ! 	7$3::66	7c 	L58] 	 	D A1M1%&-0ZZ9GGCO ww%' (   JJsO))+/C("$**R"<KC ww&( ) !8 S$/Ay<xGH

((*

((* &sCM23  #zz+ 99;#%JJqMC F +c(m;zz#	7IIaO  	7$3::6	7s<  CU U /(T U !AU 6U ?X V+(V38W" T>T92U 6X 9T>>U ;V <X ?V  X V0V++V03W>WW"&XXAb,%Y><b,>Z*	Z%b,%Z**?b,+(\b,\?	\:	5b,:\?	?C	b,b,$b,<+b,(b ?b, &b)&b,(b))b,c                 J    \        4       p\        R V ,          VR.VVR7      pV# )r   zmodules:paged_searches)r   r   optionsr   r   )r   r   )r1  r   r   r  r  s   &&&  r;   openLdbr:    s1    G
K$&$12!	C
 Jr=   c                6    RVV P                   ! 4       3,          # )z(Generate an ou name from the instance idz#ou=instance-%d,ou=traffic_replay,%s)r  )r  r   s   &&r;   ou_namer<    s"    0K47MMO4E E Er=   c                `   \        W4      p V P                  ! RVP                  R^4      ^,          RR/4        V P                  ! RVRR/4       V#   \         d!   pTP                  w  rET^D8w  d   h  Rp?L?Rp?ii ; i  \         d"   pTP                  w  rET^D8w  d   h  Rp?T# Rp?ii ; i)zCreate an ou, all created user and machine accounts will belong to it.

This allows all the created resources to be cleaned up easily.
r   r   objectclassorganizationalunitN)r<  addrr   r   r:   r  r   r   r   r  r   s   &&    r;   	create_ourB    s    
 
	"BrxxQ'* 46 	7r 46 	7 I  ffR<   ffR< Is.   -A B A>A99A>B-B((B-ConversationAccountsc                    . p\        ^V^,           4       F7  p\        W4      p\        W4      p\        WcVV4      pVP	                  V4       K9  	  V# )z;Generate a series of unique machine and user account names.)r  machine_namer"  rC  r  )	r  r   numberpasswordr2  r  r2  r4  r=  s	   &&&&     r;   generate_replay_accountsrH  ;  sV     H1fqj!#K3[,&|x'/1  " Or=   c                   \        W4      pRV: RV: 2pR\        V4      ,          P                  R4      pV'       d   \        \        \
        ,          4      pM\        \        4      pV P                  ! RVRRRR	V,          R
VRV/4       R# )z"Create a machine account via ldap.r*  r   "%s"	utf-16-ler   r>  computersAMAccountNamez%s$userAccountControl
unicodePwdN)r<  r!   encoder
  r   r   r   r@  )	r  r   r2  r3  traffic_accountr   r   utf16pwaccount_controlss	   &&&&&    r;   create_machine_accountrT  I  s     
	"B#R	(B
;//77DG 86 7 8 ;<GGbz%,..g  r=   c                   \        W4      pRV: RV: 2pR\        V4      ,          P                  R4      pV P                  ! RVRRRVR	\	        \
        4      R
V/4       \        P                  ! V 4      pVP                  VR4       R# )zCreate a user account via ldap.r*  r   rJ  rK  r   r>  userrM  rN  rO  z(A;;WP;;;PS)N)	r<  r!   rP  r@  r
  r   r    SDUtilsdacl_add_ace)r  r   r4  r5  r   r:  rR  sdutilss   &&&&    r;   create_user_accountrZ  b  s    		"B$b)G
8,,44[AGGGgv(c"34g  s#G.1r=   c                `    \        W4      pRV: RV: 2pV P                  ! RVRRRV/4       R# )zCreate a group via ldap.r*  r   r   r>  grouprM  N)r<  r@  )r  r   r/   r   r   s   &&&  r;   create_groupr]  t  s8     
	"BR	 BGGbw$ r=   c                    RW3,          # )z-Generate a user name based in the instance idz
STGU-%d-%drO   r   r  s   &&r;   r"  r"        ;***r=   c                    V P                   ! RP                  V4      V.R7      pV Uu0 uF  p\        WB,          4      kK  	  up# u upi )z(Search objectclass, return attr in a setz(objectClass={}))r   r   )r  r   r
  )r  r>  attrobjsobjs   &&&  r;   search_objectclassre    sC    ::%,,[9fD '++dsC	Nd+++s   Ac                    \        V RR7      p^ p\        V^ R4       FX  p\        W4      pWt9  g   K  \        WWs4       V^,          pV^2,          ^ 8X  g   K;  \        P                  RWR3,          4       KZ  	  V# )zAdd users to the serverrV  r>  zCreated %u/%u usersrg  )re  r  r"  rZ  r   r  )r  r   rF  rG  existing_objectsusersr  r/   s   &&&&    r;   generate_usersrj    sp    )#6BE61b!('$AQJErzQ1UOCD " Lr=   c                :    V'       d   RW3,          # RW3,          # )z1Generate a machine account name from instance id.z
STGM-%d-%dzPC-%d-%drO   )r   r  rQ  s   &&&r;   rE  rE    s%     {... [,,,r=   c                
   \        V RR7      p^ p\        V^ R4       Fb  p\        WV4      pVR,           V9  g   K  \        WWV4       V^,          pV^2,          ^ 8X  g   KE  \        P                  RWb3,          4       Kd  	  V# )z"Add machine accounts to the serverrL  rg  rZ  zCreated %u/%u machine accountsrg  )re  r  rE  rT  r   r  )	r  r   rF  rG  rQ  rh  addedr  r/   s	   &&&&&    r;   generate_machine_accountsrn    s     *#:FE61b!KO<#:--"3T#24QJErzQ<NO " Lr=   c                    RW3,          # )z'Generate a group name from instance id.z
STGG-%d-%drO   r_  s   &&r;   
group_namerp    r`  r=   c                    \        V RR7      p^ p\        V^ R4       FX  p\        W4      pWc9  g   K  \        WV4       V^,          pVR,          ^ 8X  g   K;  \        P                  RWB3,          4       KZ  	  V# )z3Create the required number of groups on the server.r\  rg  r  zCreated %u/%u groupsrg  )re  r  rp  r]  r   r  )r  r   rF  rh  groupsr  r/   s   &&&    r;   generate_groupsrs    sr    )#7CF61b!+)'40aKF}!2f5EEF " Mr=   c                    \        W4      p V P                  ! VR.4       R#   \         d"   pTP                  w  rET^ 8w  d   h  Rp?R# Rp?ii ; i)z7Remove the created accounts and groups from the server.ztree_delete:1N)r<  deleter   r:   rA  s   &&    r;   clean_up_accountsrv    sL    		"B

2() ffR< s   # AA

Ac	                H   ^ p	^ p
^ p\        W4       \        P                  R4       \        WW24      p\        P                  R4       \	        WWrV4      pV^ 8  d"   \        P                  R4       \        WV4      p
V^ 8  dW   \        P                  R4       \        VV
VVVV4      p\        P                  R4       \        WV4       VP                  4       p	V
^ 8  d#   V^ 8X  d   WJ8w  d   \        P                  R4       \        P                  RWV
V	3,          4       R# )	zMGenerate the required users and groups, allocating the users to
those groups.zGenerating dummy user accountsz!Generating dummy machine accountszGenerating dummy groupszAssigning users to groupszAdding users to groupsz(The added groups will contain no membersz:Added %d users (%d machines), %d groups and %d membershipsN)
rB  r   r  rj  rn  rs  GroupAssignmentsadd_users_to_groupsr{  warning)r  r   rG  number_of_usersnumber_of_groupsgroup_membershipsmax_membersmachine_accountstraffic_accountsmemberships_addedgroups_addedcomputers_addedusers_addedassignmentss   &&&&&&&&&     r;   generate_users_and_groupsr    s    LOc
KK01 ?MK
KK34/0@0@BO !-.&s9IJ1/0&'7'3'6'2'8'24 	,-Ck:'--/q[A-'AB
KKL|"$$ %r=   c                   b   a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )rx  i
  c                    ^ V n         V P                  V4       V P                  W54       W`n        \	        \
        4      V n        V P                  WVWE4       R# )r   N)r  generate_group_distributiongenerate_user_distributionr~  r   r  r  assign_groups)rj   r|  r  r{  r  r}  r~  s   &&&&&&&r;   rk   GroupAssignments.__init__  sQ     
(()9:''K&&t,+?&	;r=   c                    . p\        V4      pV^ 8X  d   R# RpV F"  pWE,          pVP                  WC,          4       K$  	  V# )r   Nr   )r'  r  )rj   weightsdistr{  
cumulativeprobabilitys   &&    r;   cumulative_distribution(GroupAssignments.cumulative_distribution  sI     GA:
"K%JKK
*+ # r=   c                    VR8  d   RpMVR8  d   RpMVR8  d   RpMRp. p\        ^V^,           4       F*  p\        P                  ! V4      pVP                  V4       K,  	  V P	                  V4      V n        R# )	zAProbability distribution of a user belonging to a group.
        i@KL g      @i g      @i g      @g      ?N)r  r!  paretovariater  r  	user_dist)rj   	num_usersnum_membershipsshaper  rR   rL   s   &&&    r;   r  +GroupAssignments.generate_user_distribution'  sz     W$Ew&Ev%EEq)a-(A$$U+ANN1 )
 55g>r=   c                    . p\        ^V^,           4       F$  p^VR,          ,          pVP                  V4       K&  	  W n        V P                  V4      V n        R# )z6Probability distribution of a group containing a user.g?N)r  r  group_weightsr  
group_dist)rj   r"  r  rR   rL   s   &&   r;   r  ,GroupAssignments.generate_group_distributionA  sP    
 q!a%AQVANN1 !
 %66w?r=   c                    \         P                   ! V P                  \        P                  ! 4       4      p\         P                   ! V P                  \        P                  ! 4       4      pW3# )z2Returns a randomly generated user-group membership)bisectr  r!  r  rj   rV  r\  s   &  r;   generate_random_membership+GroupAssignments.generate_random_membershipO  s@     }}T^^V]]_=doov}}?{r=   c                (    V P                   V,          # r^   )r  )rj   r\  s   &&r;   users_in_groupGroupAssignments.users_in_group[  s    &&r=   c                6    V P                   P                  4       # r^   )r  r  r   s   &r;   
get_groupsGroupAssignments.get_groups^  s    $$&&r=   c                   \        V P                  V,          4      pW28  d^   \        P                  RP	                  W4      4       ^ V P
                  V^,
          &   V P                  V P
                  4      pW@n        R# R# )z?Prevent the group's membership from exceeding the max specifiedzGroup {0} has {1} membersN)r  r  r   r  r   r  r  r  )rj   r\  r~  num_membersnew_dists   &&&  r;   cap_group_membership%GroupAssignments.cap_group_membershipa  sk    $**512%KK3::5NO -.Duqy)33D4F4FGH&O &r=   c                   WP                   V,          9  d<   V P                   V,          P                  V4       V ;P                  ^,          un        V P                  '       d   V P	                  W P                  4       R# R# r[  )r  r  r  r~  r  r  s   &&&r;   add_assignmentGroupAssignments.add_assignmentm  sb     ''..U#**40JJ!OJ %%e-=-=> r=   c                   V^ 8:  d   R# \         P                  ! \        V4      \        V4      \        V4      ,          ,          4      pV P                  '       d   \	        VV P                  V,          4      pW4,
          ^,
          pW,
          ^,
          pV P                  4       V8  dC   V P                  4       w  rW8  g	   W8  g   K5  V P                  V^,           V	^,           4       KW  R# )zAllocate users to groups.

The intention is to have a few users that belong to most groups, while
the majority of users belong to a few groups.

A few groups will contain most users, with the remaining only having a
few users.
N)ru  ceilrs   r~  rN  r{  r  r  )
rj   r|  r  r{  r  r}  existing_usersexisting_groupsrV  r\  s
   &&&&&&    r;   r  GroupAssignments.assign_groupsy  s     ! !II#$;%"88:;  #$5$($4$47G$G!I *8A=*9A=jjl..99;KD&$*? ##D1Heai8 /r=   c                    V P                   # r^   r  r   s   &r;   r{  GroupAssignments.total  s    zzr=   )r  r  r  r  r~  r  N)rV   rW   rX   rY   rk   r  r  r  r  r  r  r  r  r  r{  rZ   r   r   s   @r;   rx  rx  
  sC     	;"?4@
''
'
?9B r=   rx  c                   VP                  4       p^ p^ pVP                  4        F  pVP                  V4      p\        V4      ^ 8X  d   K&  \	        ^ \        V4      R4       Fb  pWxVR,            p	\        WWi4       V\        V	4      ,          pV^,          pV^2,          ^ 8X  g   KE  \        P                  RWS3,          4       Kd  	  K  	  R# )zDTakes the assignments of users to groups and applies them to the DB.r  zAdded %u/%u membershipsN)r{  r  r  r  r  add_group_membersr   r  )
r  r   r  r{  r  rm  r\  r  chunkchunk_of_userss
   &&&       r;   ry  ry    s     EEE'')$33E:~!#
 1c.148E+%$,?NbuES((EQJErzQ5FG 9 *r=   c                v  a
 \        W4      o
V
3R lpV! \        W4      4      p\        P                  ! 4       p\        P                  ! W4      Vn        V FN  pV! \        W4      4      pR\        V4      ,           p	\        P                  ! V\        P                  R4      Wi&   KP  	  V P                  V4       R# )z(Adds the given users to group specified.c                    < R V : RS: 2# )r*  r   rO   )r/   r   s   &r;   build_dn#add_group_members.<locals>.build_dn  s    !2&'r=   zmember-memberN)r<  rp  r  MessageDnr   r"  r
  MessageElementFLAG_MOD_ADDmodify)r  r   r\  r  r  group_dnmrV  r:  idxr   s   &&&&      @r;   r  r    s     
	!B( 
;67HA66"AD9[78#d)###GS-=-=xH 
 IIaLr=   c                	   \         P                  P                  p^ p^ p^ p/ p\        4       p\	        4       pVe   VP
                  p	MR p	V	! R4       R^ R^ R^ /p
R^ R^ R	^ /p\        P                  ! V 4       EF<  p\        P                  P                  W4      p\        VR
4      ;_uu_ 4       pV F  p VP                  R4      P                  R4      pV^,          pV^,          pV^,          p\        V^,          4      p\        V^ ,          4      p\        VV,
          V4      p\        VV4      pVV3pVP                  V. 4      P!                  V4       V^,          R8X  d   V^,          pMV^,          pVV;;,          ^,          uu&   VP#                  V4       V	! V4       K  	  RRR4       EK?  	  W2,
          pV^ 8X  d   ^ pM	VV,          pV^ 8X  d   ^ pM	VV,          p\/        V4      p\+        RV,          4       \+        RVV3,          4       \+        RVV3,          4       \1        V
P3                  4       4       F1  w  pp\+        RVP5                  RR4      R,           V3,          4       K3  	  \1        VP3                  4       4       F1  w  pp\+        RVP5                  RR4      R,           V3,          4       K3  	  \+        R4       / pV F2  w  ppVV9  d   \	        4       VV&   VV,          P#                  V4       K4  	  \1        VP7                  4       4      p V  F  p\1        VV,          \8        R7      p!V! F  pVV3pVV,          p"\1        V"4      p"\/        V"4      p#VV,          p\;        V"4      V#,          p$\=        V"R4      p%\=        V"R4      p&V"R,          V"^ ,          ,
          p'V"R,          p(\>        PA                  VR4      p)\+        RVVV)V#VV$V%V&V'V(3
,          4       K  	  K  	  R#   \$        \&        3 d    RT9   d   TP                  R^4      w  ppTT
9   d$   \        \        T4      T
T,          4      T
T&    EK  TT9   d$   \        \)        T4      TT,          4      TT&    EK  \+        T\         P,                  R7        EK  \+        T\         P,                  R7        EK  i ; i  + '       g   i     EKW  ; i)z/Generate and print the summary stats for a run.Nc                     R # r^   rO   )rR   s   &r;   twgenerate_stats.<locals>.tw  s    r=   z2time	conv	protocol	type	duration	successful	error
zMaximum lagz	Start lagzMax sleep missr  r   r"  r  rn   ro   Truer   r1   zTotal conversations:   %10dz-Successful operations: %10d (%.3f per second)z-Failed operations:     %10d (%.3f per second)z%-28s %fr   r@   z%-28s %dzProtocol    Op Code  Description                                Count       Failed         Mean       Median          95%        Range          Max)r   r#  gffffff?r{   z?%-12s   %4s  %-35s %12d %12d %12.6f %12.6f %12.6f %12.6f %12.6frg  )!r5   
float_inforO  r   r7  writer  listdirr  r|   r  rq   rr   rs   rN  r  r  r@  r  
IndexErrorrt   r4   r6   r  sortedr  replacer  
opcode_keyr'  calc_percentiler  r   )*r   timing_filerz  r|  
successfulfailed	latenciesfailuresunique_conversationsr  float_values
int_valuesr  r  rA  rv   rw   r   re   packet_typelatencyr~   opr  r  r   success_ratefailure_raterV  opsprotor  	protocolspacket_typesrQ  r  meanmedian
percentilerngmaxvrg   s*   &&                                        r;   generate_statsr    sx   ##EDJFIH5	 BC 	qQ!L 	 1"AJ JJx(ww||H/$__"5#';;t#4#:#:4#@F#)!9L#)!9H#)!9K#(#3GfQi(A#&q7{E#:E#&q$<D"K0B((R077@ayF*"a
! )(,,\:tH+  _ )P |HQ!H,{(,-M	
'-
78	
9&' (	
9\"# $ |))+,1jAIIc3/#5q99: -z'')*1jAIIc3/#5q99: + 
 * + C"vCJE
v # sxxz"Ic(m<'KK(B"2FFVE!"FVu,D(6F(6JfQi/CD(,,R4D 0 	  ( c #J/ 5d{#zz#q11,.1%(2>q//CLO*_,/A0:1-?JqM "$SZZ88 d445/ __sV   0R>7C2O;)R>;AR;R>&R;8R><R;R>R;6R>:R;;R>>Sc                N     R\        V 4      ,          #   \         d    T u # i ; i)zCSort key for the operation code to ensure that it sorts numericallyz%03d)rt   r  )r  s   &r;   r  r  L	  s)    A s    $$c                \   V '       g   ^ # \        V 4      ^,
          V,          p\        P                  ! V4      p\        P                  ! V4      pW48X  d   V \	        V4      ,          # V \	        V4      ,          WB,
          ,          pV \	        V4      ,          W#,
          ,          pWV,           # )zlCalculate the specified percentile from the list of values.

Assumes the list is sorted in ascending order.
)r  ru  floorr  rt   )rQ  r  r  rA  rj  d0d1s   &&     r;   r  r  T	  sx     	VqJ&A

1A		!Avc!f~	A15	!B	A15	!B7Nr=   c                     \         P                  P                  ! V !  p\         P                  ! ^?4      p\         P                  ! V4       \         P                  ! V4       V# )zqIn a testenv we end up with 0777 directories that look an alarming
green colour with ls. Use umask to avoid that.)r  r  r|   umaskmkdir)r  r  masks   *  r;   r6  r6  f	  s>     	dA88E?DHHQKHHTNHr=   )r$   0)r&   0x72)r'   r  )r'   3r   )r(   r  )r)   r*   )r)   14)r+   r  )r$   1)r'   r  )r'   4)r'   5)r(   r  )r)   12)r)   13r   >   r&   r,   r-   r.   )ir  r  )rn  r   )r-   0x01)r-   0x02)r-   0x08)r-   0x09)r-   0x0c)r-   0x0f)r)   r  r   )r)   r   )r   r  )r   r  )r   r   )r   r  )r   r   )r   r  )r   r  )r  r  r   )r'   r{   )r}  r  )r}  r   )r}  39)r}  40)r}  6)r}  76)r}  77)r+   r  )r  21)r  26)r  29)r  30)r  r  )r  r  )r  45)r  r  )r   r  )r   r   )r   17)r   18)r   19)r   r  )r   25)r   34)r   36)r   r  )r   r  )r   r  )r   64)r   r	  )r   7)r   8)r&   0x04)r&   0x24)r&   0x2e)r&   0x32)r&   0x71)r&   0x73)r&   0x74)r&   0x75)r&   0xa2)r,   r  )r,   r*   )r,   r  )r,   r   )r,   r  )r,   r  )r,   r   )r,   r  )r,   r  )r,   r  )r,   r	  )r,   r  )r.   0x12)r.   0x17)r   r   )r   r  )rn  r^   )	NNNNr   NNr%   F)r2  r3  r4  r5  )T)rV  rM  )yr   r  r!  r  ru  r5   r   r+  r   r   collectionsr   r   r   r   dns.resolverr	   r=  samba.emulater
   samba.samdbr   r  r   samba.dcerpcr   r   r   r   r   samba.dcerpc.netlogonr   r   r   samba.drs_utilsr   rB   samba.credentialsr   r   r   
samba.authr   
samba.dsdbr   r   r   r   samba.dcerpc.miscr   sambar   r    samba.commonr!   samba.loggerr"   r  r  r  r   rs  r   r   r   rw  rt  r  r3   rV   r   r<   rG   rS   r   rU   objectr\   r   r   r   r  r  r  rY  r_  rd  rf  rh  r  r  r  r  r  r  r  rD  r:  r<  rB  rC  rH  rT  rZ  r]  r"  re  rj  rE  rn  rp  rs  rv  r  rx  ry  r  r  r  r  r6  rO   r=   r;   <module>r4     sU  (  	    
   E E + )  
  ) / / ! 4   &  O O %  +   # )    
 #S333Ccc3
 #333Cccc	 ? 

""  	x	(6$
0	i 	O<V O<d,.$^F ^B& >d*6 d*NKW KW\2Bj+_6 _D	4D  
4	
 D D T d D d 
4 t t D d  D!&_3_6_ :_ 9	_
 ?_ ;_ O_ O_ Y_ f_ j_ j_ o_ *_ g_  Z!_" '#_$ *%_& h'_( ~)_* *+_, j-_. o/_0 &1_2 +3_4 %5_6 b7_8 =9_: >;_< ?=_> ??_@ #A_B ?C_D #E_F 'G_H &I_J 7K_L 0M_N %O_P 'Q_R (S_T 7U_V :W_X 4Y_Z 5[_\ 4]_^ 4__` 1a_b 6c_d 8e_f 3g_h Ii_j (k_l Mm_n Lo_p Kq_r 7s_t &u_v Jw_x Oy_z &{_| ?}_~ >_@ JA_B =C_D <E_F $G_H ^I_J *K_L 'M_N _O_P -Q_R 0S_T 0U_V )W_X /Y_Z ,[_\ &]_^ G__` Fa_b Ic_d Ge_f >g_h ?i_j =k_l #876D  5'o}_D<~DP7fE: ""8#/0  22$	+
,-"+
	*%ZQv QhH0(D$r=   