-
Mar 12th, 2022, 11:03 PM
#1
Thread Starter
Lively Member
Binary files inside EXCEL VBA
As advanced as it is, often even VBA excel has limitations. To overcome these shortcomings, a communication between an independent application and the excel application is an artifice that can save many automations. For example, faster processing can be done by injecting data using VBA into an external application after which the result can be returned to Excel VBA for further processing. Or, maybe we want to execute a VBA function inside EXCEL at regular time intervals.
Now the problem arises: what if this .xlsx file (VBA Excel file) needs to be used by a large mass of analysts inside a company? analysts who don't know much about software programming and automation. What do we do? Well, we can't bother them with all the technical details on where different files should pe put in or how the application works. If we do, they will simply reject your automatisation. On the other hand no programmer may wish to explain the "how to" for let's say 1000-3000 individuals, it is not feasible (i.e. resistance to new things, different training backgrounds, and so on).
The best solution is to give them one EXCEL file like they are used to. This implies that the external application (exe file) must somehow be in the same excel file.
Thus, this application from below converts any executable file to VBA source code that can be included as a '.bas' module in an EXCEL file. Once inserted into the EXCEL file, the VBA code can be used to completely restore the executable file to disk in the same directory as the EXCEL file. Also, once recomposed on disk, the executable file can be executed automatically. Use the EXCEL file in the "test" directory for experimentation.
Download: Binary files inside EXCEL VBA
Last edited by Paul A. Gagniuc; Mar 20th, 2022 at 01:42 PM.
-
Mar 14th, 2022, 01:30 AM
#2
Re: Binary files inside EXCEL VBA
Please stop posting things that are most useful for malware writers, please delete this and the other almost the same thread.
Normal programmers don't drop exes, and if someone need to do so, most advanced programmers already have the skills to write that code.
This kind of code samples can only help scrip kiddies and wannabe hackers.
TIA.
-
Mar 14th, 2022, 02:09 AM
#3
Addicted Member
Re: Binary files inside EXCEL VBA
G'Day Eduardo
I have been collecting the source code for virus written in many language for 20+ years for desktop and this technique won't get past 99% of virus detectors.
Originally Posted by Paul A. Gagniuc
completely restore the executable file to disk
as it is writing to disk not memory directly.
Don't want to same anymore about this to help the criminals.
Plus, this project is in github already, out in the wild
Are you using TOR, if not get onto DW and you would see much much worse than this avail. HAAS - Hacking as a Serv. !!!
-
Mar 14th, 2022, 02:17 AM
#4
Re: Binary files inside EXCEL VBA
The more that VB6 is used for criminal activities, the more that it hurts the (good) VB6 community.
-
Mar 14th, 2022, 02:25 AM
#5
Addicted Member
Re: Binary files inside EXCEL VBA
G'Day Eduardo
Yes mate I understand
But M$ tried to get rid of VB6 for this reason 15+ years ago and it didn't work.
I have a friend who was working for M$ back then and a few of the management team said this was like trying to ban guns because criminals use guns !!!
We cannot stop the criminals, plus we need u to get back to the coding bench and continue on with all of your gr8 coding projects.
Remember not everyone is Leonardo or Michelangelo, the community would be much better off if you just let go of this concern because it is stopping you being as product as you could be
Pls. put down your suite case of concern and walk away into the sunset.
I hope you take this as a compliment not a condescending rant.
-
Mar 14th, 2022, 02:53 AM
#6
Re: Binary files inside EXCEL VBA
The reasons why MS abandoned VB6 had nothing to do with this, and yes, we can do something: not to post stuff like this.
Originally Posted by jg.sa
We cannot stop the criminals
No, we cannot stop all criminals, but what we can do is not to help them.
jg.sa: I'm really not understanding what you are saying, what is your point, if you are in favor or against and of what. Your English is a bit strange, BTW.
It is for not helping criminals, but it is more about protecting our language and our projects. If VB6 is used for criminal activities more and more, AVs will start to flag as malware any VB6 executable. And that is to some extent already happening.
-
Mar 14th, 2022, 03:44 AM
#7
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by Eduardo-
The reasons why MS abandoned VB6 had nothing to do with this, and yes, we can do something: not to post stuff like this.
No, we cannot stop all criminals, but what we can do is not to help them.
jg.sa: I'm really not understanding what you are saying, what is your point, if you are in favor or against and of what. Your English is a bit strange, BTW.
It is for not helping criminals, but it is more about protecting our language and our projects. If VB6 is used for criminal activities more and more, AVs will start to flag as malware any VB6 executable. And that is to some extent already happening.
We must avoid finding excuses for mediocre security analysts that confuse VB6 executables with malware, we've been making this excuse for a decade or more. The method presented here is a naive approach to malware, at best. I will argue that this method does not help malware creators. And to be realistic, one can't create malware and be unaware of this method ...
We can't stop using air for breathing just because air fuels flames. At this point I believe the method is very helpful for advanced Excel VBA automation projects (hybrid projects).
Last edited by Paul A. Gagniuc; Mar 14th, 2022 at 07:24 AM.
-
Mar 14th, 2022, 12:31 PM
#8
Re: Binary files inside EXCEL VBA
Gosh, I'm on the fence on this one.
Paul seems to be providing us with some really great stuff with no ill intent at all, so I'm hesitant to give him too hard a time.
Also, I agree that this approach would be a pretty primitive approach to malware. Once someone allows the running of Excel macros, they've opened themselves up regardless of whether some binary executable is exported or not. The VBA can be quite harmful, if someone wishes to do that.
Also, whatever this binary is, it's got to be "portable" or this approach isn't going to work. Although, I suspect that most email-type viruses are portable.
IDK, I just don't see any immediate ill-intent here.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 14th, 2022, 05:29 PM
#9
Re: Binary files inside EXCEL VBA
I myself am not sure how to feel about the potential abuses techniques like this could encourage. However, I am curious as to what legitimate use something like this could have. While I don't doubt OP's honest intentions, this kind of thing smells like malware, primitive as this method of infection is.
-
Mar 15th, 2022, 11:47 AM
#10
Re: Binary files inside EXCEL VBA
Truth be told, this whole thread is a bit off-topic, being Excel VBA and all. If we're in VB6, all of this is trivial. Just shove the binaries into the project's resources and unload them from there. It's also twice as efficient (I didn't look but I believe he's using hex), as the direct binary code can be stored in the resources. Not really any secret about that at all.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 15th, 2022, 01:59 PM
#11
Re: Binary files inside EXCEL VBA
People don't typically put EXEs in a project's resource files.
-
Mar 15th, 2022, 02:06 PM
#12
Re: Binary files inside EXCEL VBA
However, after thinking about this further, I realized that there are far more advanced techniques showcased on this site that could be used towards malevolent ends and can be far more dangerous. This one is pretty basic and tame by comparison and as such, it may be acceptable to leave it up though I'd encourage it's use towards storing non executable binaries like images.
-
Mar 15th, 2022, 02:12 PM
#13
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by Elroy
Truth be told, this whole thread is a bit off-topic, being Excel VBA and all. If we're in VB6, all of this is trivial. Just shove the binaries into the project's resources and unload them from there. It's also twice as efficient (I didn't look but I believe he's using hex), as the direct binary code can be stored in the resources. Not really any secret about that at all.
To my shame, I totally forgot about the project resources. I think I used the project resources once if I vaguely remember this.
Last edited by Paul A. Gagniuc; Mar 15th, 2022 at 02:20 PM.
-
Mar 15th, 2022, 02:19 PM
#14
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by Niya
I myself am not sure how to feel about the potential abuses techniques like this could encourage. However, I am curious as to what legitimate use something like this could have. While I don't doubt OP's honest intentions, this kind of thing smells like malware, primitive as this method of infection is.
The point with EXCEL files and embedded executables is that .xlsm can allow for one file applications with no dependencies. I believe the world already craves for that. People have no time for endless instructions and disparate files. There is also a beauty in one file EXCEL applications.
-
Mar 15th, 2022, 02:35 PM
#15
Re: Binary files inside EXCEL VBA
Originally Posted by Paul A. Gagniuc
The point with EXCEL files and embedded executables is that .xlsm can allow for one file applications with no dependencies. I believe the world already craves for that. People have no time for endless instructions and disparate files. There is also a beauty in one file EXCEL applications.
Ah well, VBA is not a world I ever played in for any significant time. My last bout with VBA was building programs in Access like 20 years ago. I'll defer to you on this if you think this is an approach VBA users find acceptable.
-
Mar 15th, 2022, 03:01 PM
#16
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by Niya
Ah well, VBA is not a world I ever played in for any significant time. My last bout with VBA was building programs in Access like 20 years ago. I'll defer to you on this if you think this is an approach VBA users find acceptable.
VBA is the most powerful environment for automation, by far. Many tries to copy the model or to have some variations on it were done over time. None worked as the original.
-
Mar 15th, 2022, 03:17 PM
#17
Re: Binary files inside EXCEL VBA
Originally Posted by Paul A. Gagniuc
VBA is the most powerful environment for automation, by far. Many tries to copy the model or to have some variations on it were done over time. None worked as the original.
You should probably qualify that as "internal" automation, because VB6 and other languages can take advantage of the object model exposed by MS-Office products, and then "externally" automate them. I do that extensively with VB6. And it's really the power of programs such as Excel that make all of this so appealing.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 16th, 2022, 03:02 AM
#18
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by Elroy
You should probably qualify that as "internal" automation, because VB6 and other languages can take advantage of the object model exposed by MS-Office products, and then "externally" automate them. I do that extensively with VB6. And it's really the power of programs such as Excel that make all of this so appealing.
Indeed, "internal" automation is the right term here. I have seen this "external" approach done from VB6 and from Python in the past.
Last edited by Paul A. Gagniuc; Mar 16th, 2022 at 03:09 AM.
-
Mar 16th, 2022, 11:22 AM
#19
Re: Binary files inside EXCEL VBA
Originally Posted by Paul A. Gagniuc
The point with EXCEL files and embedded executables is that .xlsm can allow for one file applications with no dependencies. I believe the world already craves for that. People have no time for endless instructions and disparate files. There is also a beauty in one file EXCEL applications.
So you're using Excel as an install tool, or a deployment vector... why not just use an installer? Otherwise you're cutting off a segment of potential users that don't have Excel.
Originally Posted by Paul A. Gagniuc
VBA is the most powerful environment for automation, by far. Many tries to copy the model or to have some variations on it were done over time. None worked as the original.
Originally Posted by Elroy
You should probably qualify that as "internal" automation, because VB6 and other languages can take advantage of the object model exposed by MS-Office products, and then "externally" automate them. I do that extensively with VB6. And it's really the power of programs such as Excel that make all of this so appealing.
I'd argue that Exchange is pretty powerful in the automation realm. I've built workflow processes around early Exchange servers and MS Mail (and early Outlook) that automated a number of processes. All it required was for the user to open a mail of a particular type (generating a Mail Form) ... fill it out, and then based on the sender, and other values set, it would automatically route it to the appropriate people ... if it hit someone that was OOO, it bypassed them and went to the next person on the list. If it sat too long in someone's inbox (they went on vacation and forgot to turn on their OOO settings) it would timeout and bypass them. It was pretty cool. All on mid-90's tech too.
-tg
-
Mar 16th, 2022, 05:40 PM
#20
Re: Binary files inside EXCEL VBA
I think we're all getting a bit carried away here.
In my primary application (which is portable and needs no installation, but does extensively use SxS for OCXs as well as Trick tricks for loading ActiveX DLLs), in addition to that, I have two little utility programs stuffed into its "resources". One is a video player (based on MPlayer), and the other is a freeware C3D (coordinate 3 dimensions) file reader (actually written by a friend). Those are both portable as well, so I just write them out to a folder in the CSIDL_LOCAL_APPDATA area, and use them when I need them. It's all been working fine for decades.
Personally, I dislike installers a great deal, but I know there's much debate about that, so, just chalk that up to my personal opinion.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 17th, 2022, 12:10 AM
#21
Re: Binary files inside EXCEL VBA
And in that case... you can just distribute the file, right? And in that case that would be fine (personally I prefer those kinds of "installs") ...
But in regards to this thread I guess I'm failing to see what wrapping it up into a module in Excel gets you other that using Excel as a deployment vector.
-tg
-
Mar 17th, 2022, 09:44 AM
#22
Re: Binary files inside EXCEL VBA
Originally Posted by techgnome
But in regards to this thread I guess I'm failing to see what wrapping it up into a module in Excel gets you other that using Excel as a deployment vector.
Hi Tech, I don't disagree. For me, Excel would be a horrible software distribution method. However, I'm guessing that Paul does a great deal of his work in Excel's VBA, and possibly had a case where he needed some little utility program (similar to me), and just came up with this method ... and shared it.
But, I should probably let him speak for himself.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 17th, 2022, 12:47 PM
#23
Re: Binary files inside EXCEL VBA
You can just use a free utility like ZIP 2 Secure EXE. This goes beyond a simple self-extracting archive with a good set of options. It also produces an EXE having a well known code signature with good reputation, avoiding a lot of problems with "false" positives from anti-malware tools.
-
Mar 19th, 2022, 05:18 AM
#24
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
I added some explanations to the post for a real world context, where the method is needed. Perhaps this could have been helpful from the very beginning.
-
Mar 20th, 2022, 01:55 PM
#25
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by Elroy
Hi Tech, I don't disagree. For me, Excel would be a horrible software distribution method. However, I'm guessing that Paul does a great deal of his work in Excel's VBA, and possibly had a case where he needed some little utility program (similar to me), and just came up with this method ... and shared it.
But, I should probably let him speak for himself.
Thank you for the kind words Dr. Sullivan, much appreciate it. Indeed, I have worked with Renault in the past on many automation projects. It baffles the mind on how advanced these kind of VBA projects can get. The work can reach a stage in which one cannot recognize EXCEL anymore. At that level the method shown here is helpful. I added some context in the description of this post, in order to clarify the use of the method:
As advanced as it is, often even VBA excel has limitations. To overcome these shortcomings, a communication between an independent application and the excel application is an artifice that can save many automations. For example, faster processing can be done by injecting data using VBA into an external application after which the result can be returned to Excel VBA for further processing. Or, maybe we want to execute a VBA function inside EXCEL at regular time intervals.
Now the problem arises: what if this .xlsx file (VBA Excel file) needs to be used by a large mass of analysts inside a company? analysts who don't know much about software programming and automation. What do we do? Well, we can't bother them with all the technical details on where different files should pe put in or how the application works. If we do, they will simply reject your automatisation. On the other hand no programmer may wish to explain the "how to" for let's say 1000-3000 individuals, it is not feasible (i.e. resistance to new things, different training backgrounds, and so on).
The best solution is to give them one EXCEL file like they are used to. This implies that the external application (exe file) must somehow be in the same excel file.
Thus, this application from below converts any executable file to VBA source code that can be included as a '.bas' module in an EXCEL file. Once inserted into the EXCEL file, the VBA code can be used to completely restore the executable file to disk in the same directory as the EXCEL file. Also, once recomposed on disk, the executable file can be executed automatically. Use the EXCEL file in the "test" directory for experimentation.
Last edited by Paul A. Gagniuc; Mar 20th, 2022 at 02:11 PM.
-
Mar 25th, 2022, 05:01 AM
#26
Member
Re: Binary files inside EXCEL VBA
Originally Posted by Niya
Ah well, VBA is not a world I ever played in for any significant time. My last bout with VBA was building programs in Access like 20 years ago. I'll defer to you on this if you think this is an approach VBA users find acceptable.
Can confirm, I've done this in the past. Especially when using DLLs like Webview2.dll, MITAB.dll, blas.dll etc.
Originally Posted by techgnome
So you're using Excel as an install tool, or a deployment vector... why not just use an installer? Otherwise you're cutting off a segment of potential users that don't have Excel.
Unfortunately, not everyone has the capability of running msi's on their computer. VBA is highly common in businesses where users aren't able to run installers like you suggest. In these scenarios using VBA as an installer is super ideal. Bare in mind typically in these cases EXEs will also be unable to run, so the primary use case is installing DLLs in my opinion.
Last edited by sancarn; Mar 25th, 2022 at 05:09 AM.
-
Mar 25th, 2022, 09:05 AM
#27
Re: Binary files inside EXCEL VBA
Originally Posted by sancarn
Can confirm, I've done this in the past. Especially when using DLLs like Webview2.dll, MITAB.dll, blas.dll etc.
Unfortunately, not everyone has the capability of running msi's on their computer. VBA is highly common in businesses where users aren't able to run installers like you suggest. In these scenarios using VBA as an installer is super ideal. Bare in mind typically in these cases EXEs will also be unable to run, so the primary use case is installing DLLs in my opinion.
That has got to be an IT nightmare...
-tg
-
Mar 25th, 2022, 10:05 AM
#28
Member
Re: Binary files inside EXCEL VBA
Originally Posted by techgnome
That has got to be an IT nightmare...
Yes, unfortunately, for both parties. A nightmare for users because they are left to maintain applications in archaic programming languages like VBA. And a nightmare for IT because Mike from accounting has retired and now IT need to maintain his archaic VBA project
-
Mar 25th, 2022, 10:27 AM
#29
Thread Starter
Lively Member
Re: Binary files inside EXCEL VBA
Originally Posted by sancarn
Yes, unfortunately, for both parties. A nightmare for users because they are left to maintain applications in archaic programming languages like VBA. And a nightmare for IT because Mike from accounting has retired and now IT need to maintain his archaic VBA project
I wish to add that VBA is made in the past, but is far from archaic. New applications are made in it. Actually I will dare to say it is way superior to many "moden" scripting languages.
-
Mar 25th, 2022, 12:04 PM
#30
Re: Binary files inside EXCEL VBA
Originally Posted by Paul A. Gagniuc
Actually I will dare to say it is way superior to many "moden" scripting languages.
First class functions, Async/Await and a straightforward multithreading API, I haven't touched VBA in eons but if the language doesn't support at least one of these then I'd hesitate to call it modern. Nearly all respectable modern languages have all of these.
Last edited by Niya; Mar 25th, 2022 at 12:11 PM.
-
Mar 25th, 2022, 12:29 PM
#31
Re: Binary files inside EXCEL VBA
Originally Posted by Paul A. Gagniuc
I wish to add that VBA is made in the past, but is far from archaic. New applications are made in it. Actually I will dare to say it is way superior to many "moden" scripting languages.
I agree. What is archaic is the VBA IDE and because it lacks of some modern technologies like Niya pointed, but not the language.
-
Mar 25th, 2022, 12:51 PM
#32
Re: Binary files inside EXCEL VBA
Originally Posted by Eduardo-
I agree. What is archaic is the VBA IDE and because it lacks of some modern technologies like Niya pointed, but not the language.
A better IDE is definitely a must but a lot of modern language features are actually implemented in the compiler. For example, Async/Await is possible due to some very advanced wizardry in modern compilers.
-
Mar 25th, 2022, 01:18 PM
#33
Member
Re: Binary files inside EXCEL VBA
Originally Posted by Niya
First class functions, Async/Await and a straightforward multithreading API, I haven't touched VBA in eons but if the language doesn't support at least one of these then I'd hesitate to call it modern. Nearly all respectable modern languages have all of these.
This. I love VB6/VBA, but I have to agree with this. Other mistakes in my opinion:
- Lack of lambda expressions
- Lack of low-level object pointers (even if the pointer was to a slug containing the objptr and used IDispatch calls)
- Lack of easy ability to implement IEnumVARIANT (or rather the lack of an alternative means to get `for each ... in ...` working) (p.s. i know libraries have made this easier)
- Lack of easy ability to implement system interfaces (related to above) (p.s. i know libraries have made this easier)
- Lack of ability to alias types (not a must have but very much a nice to have)
And to be honest you just need to look at TwinBASIC to see what's missing from VB6/VBA...
So all in all, yes, legacy/archaic and outdated. If we all had Ruby/Python installed on our machines by default, I'm pretty sure most companies would use those languages instead, apart from for very small applications where integration with Excel/Powerpoint/Word events is required.
Last edited by sancarn; Mar 25th, 2022 at 01:25 PM.
-
Mar 25th, 2022, 02:41 PM
#34
Re: Binary files inside EXCEL VBA
Originally Posted by sancarn
[*] Lack of easy ability to implement IEnumVARIANT (or rather the lack of an alternative means to get `for each ... in ...` working) (p.s. i know libraries have made this easier)
This one is quite interesting. Modern languages have some pretty interesting ways of handling collections. For example in Python one can do this:-
Code:
names = ["John","Keston","Mary","Luis"]
enumerable = iter(names)
print(next(enumerable))
print(next(enumerable))
print(next(enumerable))
print(next(enumerable))
You can also do stuff like this:-
Code:
def namesGenerator():
yield "John"
yield "Keston"
yield "Mary"
yield "Luis"
for n in namesGenerator():
print(n)
Both versions of the above produces this output:-
Code:
John
Keston
Mary
Luis
Even VB.Net supports this:-
Code:
Module Module1
Sub Main()
For Each n In namesGenerator()
Debug.WriteLine(n)
Next
Console.ReadKey()
End Sub
Private Iterator Function namesGenerator() As IEnumerable(Of String)
Yield "John"
Yield "Keston"
Yield "Mary"
Yield "Luis"
End Function
End Module
You can even combine it with another modern feature, anonymous functions:-
Code:
Module Module1
Sub Main()
Dim namesGenerator = Iterator Function()
Yield "John"
Yield "Keston"
Yield "Mary"
Yield "Luis"
End Function
For Each n In namesGenerator()
Debug.WriteLine(n)
Next
Console.ReadKey()
End Sub
End Module
Aside from Python and VB.Net, all of these are also supported in Java, JavaScript, C#, PHP, Perl and Ruby just to name a few of the more popular languages. VBA has quite a ways to go to be considered a modern language.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|