o
    jc                     @   s   d dl 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 Z	dd Z
dd	 Zd
d Zdd Zdd Zdd ZedkrEe
  dS dS )    N)version)CCachec                  C   s>   t  } | jddd | jddd | jdddd	d
 |  S )N
input_filez)File in kirbi (KRB-CRED) or ccache format)helpoutput_filezOutput filez-bz--base64
store_truez3Decode input ticket from base64 with unwrap support)actionr   )argparseArgumentParseradd_argument
parse_args)parser r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/../../../bin/ticketConverter.pyr   (   s   r   c                  C   s   t tj t } | jr"tjddd}t d |t| j	 |
  | jr(|jn| j	}t|r>t d t|| j t d nt|rQt d t|| j t d nt d | jrtz|  t|j W d S  tys   t d	 Y d S w d S )
Nzw+bF)modedeletez[*] base64 decoding ticketz![*] converting kirbi to ccache...z[+] donez![*] converting ccache to kirbi...z[X] unknown file formatz:[!] Failed to clean temporary files due to PermissionError)printr   BANNERr   base64tempfileNamedTemporaryFilewritebase64_decode_with_unwrapr   flushnameis_kirbi_fileconvert_kirbi_to_ccacher   is_ccache_fileconvert_ccache_to_kirbicloseosunlinkPermissionError)argsdecoded_filer   r   r   r   main2   s2   


r%   c                 C   N   t | d}td|dd }W d    |dkS 1 sw   Y  |dkS )Nrb>B   r   v   openstructunpackreadfilenamefifileidr   r   r   r   S      
r   c                 C   r&   )Nr'   r(   r)   r      r+   r0   r   r   r   r   Y   r4   r   c                 C      t | }|| d S N)r   loadKirbiFilesaveFileinput_filenameoutput_filenameccacher   r   r   r   _      
r   c                 C   r6   r7   )r   loadFilesaveKirbiFiler:   r   r   r   r   d   r>   r   c                 C   sZ   t | ddd}d|   }t|d}W d    |S 1 s&w   Y  |S )Nrzlatin-1)encoding )r,   joinr/   strip
splitlinesr   	b64decodeencode)r;   fdatar   r   r   r   i   s   
r   __main__)r    r	   r   r-   r   impacketr   impacket.krb5.ccacher   r   r%   r   r   r   r   r   __name__r   r   r   r   <module>   s"   
!
