본문 바로가기
debug/0x0a-pwn

CFdManager(파일 관리자 )

by SpeeDr00t 2016. 11. 22.
반응형

CFdManager(파일 관리자 )

1. 소스

  
'''
    write by SpeeDr00t

'''



from pwn import *




class CFdManager :

    def __init__(self) :

        self.path = []
        self.current_path = ''
        self.path_list = []
        self.fd = []
        self.current_fd = ''
        self.fd_count = 0

  
    def do_print( self ) :

        print "current path = %s, fd = %s " %( self.get_current_path(), self.get_current_fd() ) 


    def append_file_open(self, _path ) :
       
        print "\n\n\n\n #### path =  %s " % ( _path )

 
        self.path.append(_path)        
        self.fd.append(open( _path , 'r' ))

        self.current_path = self.path[ len(self.path) -1 ]
        self.current_fd = self.fd[ len(self.fd) -1 ] 

    def pop(self) :

        if( len(self.path ) != 0 or len(self.fd) != 0 ) :
            p_fd = self.fd.pop().close()
            p_path = self.path.pop()

            print "pop path = %s, fd.pop() = %s " \
             % ( p_path , p_fd ) 


            if( len(self.path ) != 0 or len(self.fd) != 0 ) :

                self.current_path = self.path[ len(self.path) -1 ]
                self.current_fd = self.fd[ len(self.fd) -1 ]


    def get_current_fd( self ) :

        return  self.current_fd

    def get_current_path( self ) :

        return self.current_path


    def get_current_fd_count( self ) :
 
        return self.fd_count


if __name__ == "__main__":
    
    c = CFdManager()

    cfg_path = os.getenv('AUTO_EXPLOIT')

    print cfg_path
    
    c.append_file_open( cfg_path + "/command_cfg/test1.cfg")    
    c.do_print()

    c.append_file_open( cfg_path + "/command_cfg/test.cfg")    
    c.do_print()

    c.pop()
    c.do_print()

    


실행


반응형