Jump to content

Hidden file reappear after getting replaced


Recommended Posts

Hi Guys,

I need to hide my config file because my software is using those file for updating. Apparently people knows the setting and they modified that file as they want.

This is causing my software to behave abnormal.

I tried to hide the file using attrib +HS. but when the file get replaced, the file appear again using new attrib without HS.

Is there anyway to force even if get replaced it will use the old file attribute?

Thanks guys

Link to comment
Share on other sites

Hi @apiznse, and welcome to the AutoIt forum :)
You can use a program like WinRAR or 7-Zip to create a self-extracting archive, so, when you update your file(s), their properties remain unchanged.
There are a lot UDF about Data compression, if you don't want to display things ;) 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

1 hour ago, FrancescoDiMuro said:

Hi @apiznse, and welcome to the AutoIt forum :)
You can use a program like WinRAR or 7-Zip to create a self-extracting archive, so, when you update your file(s), their properties remain unchanged.
There are a lot UDF about Data compression, if you don't want to display things ;) 

Hi FrancescoDiMuro,

 

Thanks for the tips.

Unfortunately i dont think it is applicable in my situation.

To make things clearer.

I'm handling system software for manufacturing. I have a software that using ini files to works.

Inside ini file also have option to bypass some test. Operator always went to this file and replace the dont bypass option into bypass.

The software already have password. But they are using backdoor step straight open as notepad and edit.

After each part process, this INI file will be dynamically updated. thus i cannot use Zip function.

i already have the function to detect which part was changed inside the INI file. 

In the meantime I want to try to hide the config, while maintaining it attrib even if the file get replaced. Because operator knows where the file location.

It would be hard to change the file path as multiple software is accessing the same file. I need to recompile all 3/4 software.

My code is:

 Func Lock()
   $iStatus = IniReadSection($iFilePath,"Status")
   $sInvent = FileSetAttrib ("C:\Windows\Inv_3.0.ini","+HS")
   $sInvent = FileSetAttrib ("C:\etp\Config\etp.ini","+HS")
   MsgBox(0,"","Success lock")
 EndFunc

 Func Unlock()
   Local $iKeyin
   Local $iPassBox =InputBox("Password needed","Please enter the password to proceed", "", "*")
   If $iPassBox = "SystemIT123$" Then
      $sInvent = FileSetAttrib ("C:\Windows\Inv_3.0.ini","-HS")
      $sInvent = FileSetAttrib ("C:\etp\Config\etp.ini","-HS")
      MsgBox(0,"", "Success")
   Else
      MsgBox(0,"WARNING!", "Wrong Password!")
   EndIf

 EndFunc

 

I've tested this and when i create new file with the same name. It will replaced the ini file and it attributes. 

Hence the file will reappear.

Link to comment
Share on other sites

24 minutes ago, apiznse said:

I have a software that using ini files to works.

Is this software created with AutoIt?
I'm asking this because you could use some crypting/decrypting methods, like this:

#include <Crypt.au3>
#include <File.au3>

Global $strFileName = @ScriptDir & "\NotCryptedFile.ini", _
       $strCryptedFileName = @ScriptDir & "\CryptedFile.ini", _
       $arrFileContent

; Read the content of the file before encryption
_FileReadToArray($strFileName, $arrFileContent, $FRTA_NOCOUNT)
If @error Then
    ConsoleWrite("Error while reading the file '" & $strFileName & "' in the array. Error: " & @error & @CRLF)
Else
    ; Content of the file Before the encryption
    _ArrayDisplay($arrFileContent, "Before crypting the file:")

    ; Crypting of the file
    _Crypt_EncryptFile($strFileName, $strCryptedFileName, "abcd", $CALG_3DES)
    If @error Then
        ConsoleWrite("Error while crypting the file '" & $strFileName & "'.Error: " & @error & @CRLF)
    Else
        ; If the encryption has been done, then delete the file not encrypted
        FileDelete($strFileName)

        ; Read the content of the file after encryption
        _FileReadToArray($strCryptedFileName, $arrFileContent, $FRTA_NOCOUNT)
        If @error Then
            ConsoleWrite("Error while reading the file '" & $strCryptedFileName & "' in the array. Error: " & @error & @CRLF)
        Else

            ; Content of the file after encryption
            _ArrayDisplay($arrFileContent, "After crypting the file:")

            ; Decrypt the file
            _Crypt_DecryptFile($strCryptedFileName, $strFileName, "abcd", $CALG_3DES)
            If @error Then
                ConsoleWrite("Error while decrypting the file '" & $strFileName & "'. Error: " & @error & @CRLF)
            Else

                ; Read the content of the file after decryption
                _FileReadToArray($strFileName, $arrFileContent, $FRTA_NOCOUNT)
                If @error Then
                    ConsoleWrite("Error while reading the file '" & $strFileName & "' in the array. Error: " & @error & @CRLF)
                Else
                    ; Content of the file after decryption
                    _ArrayDisplay($arrFileContent, "After decrypting the file:")
                EndIf
            EndIf
        EndIf
    EndIf
EndIf

Just create a .ini file named "NotCryptedFile.ini", and run the code above.
Tell me if it could fit your request :)

Cheers :)
 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I got exemple of encrypting data in autoit if needed pm me./

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

You could just store encrypted values in the INI file and decrypt after reading.

You could even have another INI entry that is a timestamp, that is the encryption password, that changes after every use ... so self updating if using current time each time.

 

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

@apiznse I would like to address the fact that you are not responsible for any abnormal behaviour caused by modification of your INI files, the responsibility should be fully on the "operator" who works on the manufacturing system. It really isn't possible to "secure" your software from being modified when the computer is not in your control

So I would recommend educating the operators and transfer the responsibility to them, Ideally they wouldn't need a software to baby sit them if they are working on a manufacturing system.

If you still insist on somehow dettering or discouraging this behaviour, you should try @AutoBert's solution of removing these options from the production version... but if you don't want to even do that, then I'd recommend applying some kind of encryption/obfuscation as suggested by @TheSaint.

You have to remember that you cannot fully make sure that they don't change anything which can modify the behaviour, the user is responsible for what the software does, not the developer!

Edited by TheDcoder
Complete the post...

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

I can add anyway you use for encoding your *.ini .... Nothing will dodge the fact that the user will always be able to corrupt used data.

 

If it s not by bypassing your option it will be possible to enter wrong data inside your ini that will make it crash anyway.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Hello,

You could use the ini values in a way, that they must present some secret string, if not present or not as expected, then the options will work "default".

An easy way to do so might be the hash code of the EXE file, that will change every time you rollout a new version. Have a look at

 

C:\Program Files (x86)\AutoIt3\Examples\Helpfile\_Crypt_HashFile.au3

 

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

21 hours ago, FrancescoDiMuro said:

Is this software created with AutoIt?
I'm asking this because you could use some crypting/decrypting methods, like this:

#include <Crypt.au3>
#include <File.au3>

Global $strFileName = @ScriptDir & "\NotCryptedFile.ini", _
       $strCryptedFileName = @ScriptDir & "\CryptedFile.ini", _
       $arrFileContent

; Read the content of the file before encryption
_FileReadToArray($strFileName, $arrFileContent, $FRTA_NOCOUNT)
If @error Then
    ConsoleWrite("Error while reading the file '" & $strFileName & "' in the array. Error: " & @error & @CRLF)
Else
    ; Content of the file Before the encryption
    _ArrayDisplay($arrFileContent, "Before crypting the file:")

    ; Crypting of the file
    _Crypt_EncryptFile($strFileName, $strCryptedFileName, "abcd", $CALG_3DES)
    If @error Then
        ConsoleWrite("Error while crypting the file '" & $strFileName & "'.Error: " & @error & @CRLF)
    Else
        ; If the encryption has been done, then delete the file not encrypted
        FileDelete($strFileName)

        ; Read the content of the file after encryption
        _FileReadToArray($strCryptedFileName, $arrFileContent, $FRTA_NOCOUNT)
        If @error Then
            ConsoleWrite("Error while reading the file '" & $strCryptedFileName & "' in the array. Error: " & @error & @CRLF)
        Else

            ; Content of the file after encryption
            _ArrayDisplay($arrFileContent, "After crypting the file:")

            ; Decrypt the file
            _Crypt_DecryptFile($strCryptedFileName, $strFileName, "abcd", $CALG_3DES)
            If @error Then
                ConsoleWrite("Error while decrypting the file '" & $strFileName & "'. Error: " & @error & @CRLF)
            Else

                ; Read the content of the file after decryption
                _FileReadToArray($strFileName, $arrFileContent, $FRTA_NOCOUNT)
                If @error Then
                    ConsoleWrite("Error while reading the file '" & $strFileName & "' in the array. Error: " & @error & @CRLF)
                Else
                    ; Content of the file after decryption
                    _ArrayDisplay($arrFileContent, "After decrypting the file:")
                EndIf
            EndIf
        EndIf
    EndIf
EndIf

Just create a .ini file named "NotCryptedFile.ini", and run the code above.
Tell me if it could fit your request :)

Cheers :)
 

Wow impressive stuff. I might use it for another project. Thanks!.

 

To answer your question. No my software is visual C++. Very old software just maintained by me.

I dont want to messed up the code by doing major adjustment thats why im trying to do a continous check file should be hidden even after replaced.

I come out with a workaround although in progress.

=======================================================

While 1 ; 1 for infinite loop

;------------------------------------------------------------
   Local $iFilePath = ("C:\HP\map_drives\do not delete this folder.ini")
   $iStatus = IniRead($iFilePath,"Status","Status","Unknown")
   If $iStatus = ("UH") Then
      ;do nothing
   Else
      $aInvent = FileGetAttrib("C:\Windows\Invent_3.0.ini")
      $aEtpanel = FileGetAttrib("C:\etpanel\Config\etpanel.ini")
      ;MsgBox(0,"", $aInvent & " / " & $aEtpanel) ;Hidden is ASH. Un hide is A
      If $aInvent <> ("ASH") Then
         MsgBox(0,"",$aInvent)
         ;Call ("Lock")
         $sInvent = FileSetAttrib ("C:\Windows\Invent_3.0.ini","+HS")
         _FileWriteLog($pathChangelog,@ComputerName & " "& @UserName &" invent re-locked!")
      EndIf
      If $aEtpanel <> ("ASH") Then
         ;Call ("Lock")
         $sEtpanel = FileSetAttrib ("C:\etpanel\Config\etpanel.ini","+HS")
         _FileWriteLog($pathChangelog,@ComputerName & " "& @UserName &" etpanel re-locked!")
      EndIf
      ;IniWrite ($iFilePath,"Status","Status","UH")
   EndIf

WEnd

======================================

 

So i create an ini file for status. If status is UH means i want the file to be unhide and not been re-hide.

if status is other then means i already done used the config and i already hide it. So whenever someone clever enough to replaced the file. AutoIt will autohide it again. (File obviously already replaced but its fine for now)

Unfortunately $sInvent = FileSetAttrib ("C:\Windows\Invent_3.0.ini","+HS") was denied. 

I need to enable #RequireAdmin to access windows file. However other function in this same code need to access network drive. I have tried several times; Whenever Admin is enabled autoit cannot get to the network drive. so I need to comment this ;#RequireAdmin.

Other ways is to create another exe with the requireadmin function and call. But I want to try combine in one exe only.

 

Link to comment
Share on other sites

19 hours ago, TheDcoder said:

@apiznse I would like to address the fact that you are not responsible for any abnormal behaviour caused by modification of your INI files, the responsibility should be fully on the "operator" who works on the manufacturing system. It really isn't possible to "secure" your software from being modified when the computer is not in your control

So I would recommend educating the operators and transfer the responsibility to them, Ideally they wouldn't need a software to baby sit them if they are working on a manufacturing system.

If you still insist on somehow dettering or discouraging this behaviour, you should try @AutoBert's solution of removing these options from the production version... but if you don't want to even do that, then I'd recommend applying some kind of encryption/obfuscation as suggested by @TheSaint.

You have to remember that you cannot fully make sure that they don't change anything which can modify the behaviour, the user is responsible for what the software does, not the developer!

I agree @TheDcoder. It just that, whenever wrong modification happen I need to get to know what was happening in order to debug. Operator b*lls*it answer is always "I don't know, it suddenly happen" or "This happen in other shift. I don't know". 

Yes, I had to follow @AutoBert solution if this is getting out of control. 

Handling people is very hard. 

Link to comment
Share on other sites

Just another note. If someone knows the name of the file it’s enough to go inside the folder and append the file name in the adressbar, even when it’s hidden. So you don’t have to make it visible if you want to edit but on the other hand the user can act the same way.

Simpel

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

1 hour ago, Simpel said:

Just another note. If someone knows the name of the file it’s enough to go inside the folder and append the file name in the adressbar, even when it’s hidden. So you don’t have to make it visible if you want to edit but on the other hand the user can act the same way.

Simpel

Wow it is new knowledge for me. HAHA im so bad.

Then to edit my config I can just autoit the directory into browser or run and no need for unhide again. This just simplified my code much smaller!
Thanks @Simpel

Link to comment
Share on other sites

In the past, I have used what I consider to be a simple solution to this. I put the INI file somewhere on the network that I have full rights to access but users have read-only access. Then I use a variable for the UNC to the INI file. Users can read the INI file without issue; they cannot change the contents of the INI. I use this method a lot so that when some things change, I simply change the INI file myself and it's instantly changed for all the users as well. NOTE: I also include code to check to see if the user can "see" the INI file.

Who lied and told you life would EVER be fair?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...