ó
"b<]c           @  sÇ  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d d l m Z d d l m	 Z	 d d l m
 Z
 d d l m Z e r¯ d  d l m Z d  d	 l m Z m Z n d  d
 l m Z m Z m Z y$ d  d l m Z d  d l m Z Wn- e k
 rd  d l Z d  d l m Z n Xy d  d l m Z Wn! e k
 rVd  d l m Z n Xd g Z d d „ Z d a d d „ Z d „  Z  d e f d „  ƒ  YZ! d d d „  ƒ  YZ" d d d „  ƒ  YZ# d S(   iÿÿÿÿ(   t   print_functionNi   (   t   webapi(   t   net(   t   utils(   t   PY2(   t   SimpleHTTPRequestHandler(   t
   HTTPServert   BaseHTTPRequestHandler(   R   R   R   (   t   parse(   t   unquote(   t   BytesIOt	   runsimples   0.0.0.0i  c           sŽ   d d l  } d d l ‰ d d l ‰ d d l ‰ d t j f ‡ ‡ ‡ f d †  ƒ  Y‰  d | j t f ‡  f d †  ƒ  Y} | |  | ƒ j ƒ  d S(   s4  
      Runs a simple HTTP server hosting WSGI app `func`. The directory `static/` 
      is hosted statically.
    
      Based on [WsgiServer][ws] from [Colin Stewart][cs].
      
    [ws]: http://www.owlfish.com/software/wsgiutils/documentation/wsgi-server-api.html
    [cs]: http://www.owlfish.com/
      iÿÿÿÿNt   WSGIHandlerc             sM   e  Z ‡  ‡ ‡ f d  †  Z e Z e Z e Z d „  Z d d „ Z d „  Z	 RS(   c           sB  t  j  d |  j ƒ \ } } } } } } i d d 6d d 6|  j d 6t j d 6d d	 6d d
 6d d 6|  j d 6|  j d 6| d 6| d 6|  j j d d ƒ d 6|  j j d d ƒ d 6|  j d d 6|  j	 j
 d d 6t |  j	 j
 d ƒ d 6|  j d 6} x= |  j j ƒ  D], \ } }	 |	 | d | j d d ƒ j ƒ  <qWd |  _ g  |  _ y½ |  j	 j | |  j ƒ }
 yO z+ x$ |
 D] } | rm|  j | ƒ qmqmWWd  t |
 d ƒ r­|
 j ƒ  n  XWnO ˆ j k
 rê} | j d ˆ  j ˆ  j f k rd  Sn ˆ j k
 r } d  SXWn  t ˆ j ƒ  d t j ƒn X|  j s>|  j d ƒ n  d  S(    Ns   http://dummyhost%si   i    s   wsgi.versiont   https   wsgi.url_schemes
   wsgi.inputs   wsgi.errorss   wsgi.multithreads   wsgi.multiprocesss   wsgi.run_oncet   REQUEST_METHODt   REQUEST_URIt	   PATH_INFOt   QUERY_STRINGs   Content-Typet    t   CONTENT_TYPEs   Content-Lengtht   CONTENT_LENGTHt   REMOTE_ADDRt   SERVER_NAMEt   SERVER_PORTt   SERVER_PROTOCOLs   HTTP_%st   -t   _t   closet   filet    (   i   i    (    t   urlparset   patht   rfilet   syst   stderrt   commandt   headerst   gett   client_addresst   servert   server_addresst   strt   request_versiont   itemst   replacet   uppert   wsgi_sent_headerst   wsgi_headerst   appt   wsgi_start_responset   wsgi_write_datat   hasattrR   t   errort   argst   ECONNABORTEDt   EPIPEt   timeoutt   printt
   format_exct   webt   debug(   t   selft   protocolt   hostR   t
   parameterst   queryt   fragmentt   envt   http_headert
   http_valuet   resultt   datat
   socket_errt   socket_timeout(   t   errnot   sockett	   traceback(    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   run_wsgi_app-   sP    (




$				c         S  s3   |  j  j d ƒ r% t j j |  ƒ n
 |  j ƒ  d  S(   Ns   /static/(   R   t
   startswitht   SimpleHTTPServerR   t   do_GETRM   (   R=   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRP   a   s    c         S  s.   |  j  r t d ƒ ‚ n  | | f |  _ |  j S(   Ns5   Headers already sent and start_response called again!(   R.   t	   ExceptionR/   R2   (   R=   t   response_statust   response_headerst   exc_info(    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR1   g   s    	c         S  s©   |  j  s• |  j \ } } | | j d ƒ  } | | j d ƒ d } |  j t | ƒ | ƒ x$ | D] \ } } |  j | | ƒ q_ W|  j ƒ  d |  _  n  |  j j | ƒ d  S(   NR   i   (	   R.   R/   t   findt   send_responset   intt   send_headert   end_headerst   wfilet   write(   R=   RG   t   statusR$   t   status_codet
   status_msgt   headert   value(    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR2   m   s    	
N(
   t   __name__t
   __module__RM   t   do_POSTt   do_PUTt	   do_DELETERP   t   NoneR1   R2   (    (   RJ   RK   RL   (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR   +   s   0	t
   WSGIServerc             s   e  Z ‡  f d  †  Z RS(   c           s,   t  j  j |  | ˆ  ƒ | |  _ d |  _ d  S(   Ni    (   R   t   __init__R0   t   serverShuttingDown(   R=   t   funcR(   (   R   (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRh   |   s    	(   Ra   Rb   Rh   (    (   R   (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRg   z   s   (	   t   SocketServerRK   RJ   RL   RO   R   t   ThreadingMixInR   t   serve_forever(   Rj   R(   Rk   Rg   (    (   R   RJ   RK   RL   s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   runbasic   s    
%O"c         C  so   t  |  ƒ }  t |  ƒ }  t | |  ƒ a t j r3 n  y t j ƒ  Wn' t t f k
 rj t j ƒ  d a n Xd S(   sœ   
    Runs [CherryPy][cp] WSGI server hosting WSGI app `func`. 
    The directory `static/` is hosted statically.
    
    [cp]: http://www.cherrypy.org
    N(
   t   StaticMiddlewaret   LogMiddlewareRg   R'   t   ssl_adaptert   startt   KeyboardInterruptt
   SystemExitt   stopRf   (   Rj   R(   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR   †   s    	

c         C  sB   d d l  m } | j |  | d d ƒ} t j j d ƒ | _ | S(   s²   Creates CherryPy WSGI server listening at `server_address` to serve `wsgi_app`.
    This function can be overwritten to customize the webserver or use a different webserver.
    iÿÿÿÿ(   t   wsgit   server_namet	   localhostt   java(   t   cherootRv   t   ServerR!   t   platformRN   t   nodelay(   R(   t   wsgi_appRv   R'   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRg   œ   s    t	   StaticAppc           B  sG   e  Z d  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s*   WSGI application for serving static files.c         C  s   g  |  _  | |  _ | |  _ d  S(   N(   R$   t   environt   start_response(   R=   R€   R   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRh   ©   s    		R   c         C  s!   t  t | ƒ ƒ d | |  _ d  S(   NR   (   R)   RW   R\   (   R=   R\   t   msg(    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRV   ®   s    c         C  s   |  j  j | | f ƒ d  S(   N(   R$   t   append(   R=   t   nameR`   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRX   ±   s    c         C  s   d  S(   N(    (   R=   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRY   ´   s    c          G  s   d  S(   N(    (   t   a(    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   log_message·   s    c   	      c  s  |  j  } | j d d ƒ |  _ | j d d ƒ | j d d ƒ f |  _ | j d d ƒ |  _ t ƒ  |  _ y‰ |  j |  j ƒ } d t j j	 | ƒ } | j d ƒ } |  j
 d	 | ƒ | | k rî |  j d
 d ƒ |  j |  j |  j ƒ t ƒ  ‚ n  Wn t k
 rn X|  j ƒ  } |  j |  j |  j ƒ | rid } x( t r[| j | ƒ } | sSPn  | Vq4W| j ƒ  n |  j j ƒ  } | Vd  S(   NR   R   R   R   t   REMOTE_PORTR   s   "%s"t   HTTP_IF_NONE_MATCHt   ETagi0  s   Not Modifiedi @  (   R€   R%   R   R&   R#   R
   RZ   t   translate_patht   ost   getmtimeRX   RV   R   R\   R$   t   StopIterationt   OSErrort	   send_headt   Truet   readR   t   getvalue(	   R=   R€   R   t   etagt   client_etagt   ft
   block_sizet   bufR`   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   __iter__º   s8    	'		(	   Ra   Rb   t   __doc__Rh   RV   RX   RY   R†   R˜   (    (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR   ¦   s   				Ro   c           B  s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   s)   WSGI middleware for serving static files.s   /static/c         C  s   | |  _  | |  _ d  S(   N(   R0   t   prefix(   R=   R0   Rš   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRh   ß   s    	c         C  sT   | j  d d ƒ } |  j | ƒ } | j |  j ƒ r@ t | | ƒ S|  j | | ƒ Sd  S(   NR   R   (   R%   t   normpathRN   Rš   R   R0   (   R=   R€   R   R   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   __call__ã   s
    c         C  s5   t  j t | ƒ ƒ } | j d ƒ r1 | d 7} n  | S(   Nt   /(   t	   posixpathR›   R	   t   endswith(   R=   R   t   path2(    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR›   ë   s    (   Ra   Rb   R™   Rh   Rœ   R›   (    (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRo   Ü   s   	Rp   c           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s'   WSGI middleware for logging the status.c           sS   | |  _  d |  _ t ƒ  ‰  d d ‡  f d †  ƒ  Y} t | ƒ  d  d  ƒ j |  _ d  S(   Ns   %s - - [%s] "%s %s %s" - %st
   FakeSocketc             s   e  Z ‡  f d  †  Z RS(   c           s   ˆ  S(   N(    (   R=   R…   (   R•   (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   makefileü   s    (   Ra   Rb   R¢   (    (   R•   (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR¡   ú   s   (    (   R0   t   formatR
   R   Rf   t   log_date_time_string(   R=   R0   R¡   (    (   R•   s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRh   õ   s    			c           s%   ‡  ‡ ‡ f d †  } ˆ j  ˆ  | ƒ S(   Nc           s&   ˆ |  | | Œ } ˆ j  |  ˆ  ƒ | S(   N(   t   log(   R\   RS   R5   t   out(   R€   R=   R   (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   xstart_response  s    (   R0   (   R=   R€   R   R§   (    (   R€   R=   R   s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRœ     s    c   
      C  s¢   | j  d t j ƒ } | j  d d ƒ } | j  d d ƒ } | j  d d ƒ } d | j  d d ƒ | j  d	 d ƒ f } |  j ƒ  } |  j | | | | | | f }	 d  S(
   Ns   wsgi.errorsR   R   t   ACTUAL_SERVER_PROTOCOLR   R   s   %s:%sR   R‡   (   R%   R;   R<   R¤   R£   (
   R=   R\   R€   t   outfilet   reqR>   t   methodR?   t   timeR‚   (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyR¥     s    (	(   Ra   Rb   R™   Rh   Rœ   R¥   (    (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyRp   ò   s   			(   s   0.0.0.0i  (   s   0.0.0.0i  (    (    ($   t
   __future__R    R!   R‹   t   urllibRž   R   R   R;   R   R   t
   py3helpersR   RO   R   t   BaseHTTPServerR   R   t   http.serverR   R   t   urllib.parseR	   t   ImportErrort   ioR
   t   StringIOt   __all__Rn   Rf   R'   R   Rg   R   Ro   Rp   (    (    (    s§   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/httpserver.pyt   <module>   s:   	g	
6