Apr 9, 2017 08:12 PM
(This post was last modified: Apr 9, 2017 08:53 PM by CollinChaffin.)
So, I've been reading some threads from some folks just starting out in programming specific to security asking for advice on where to start.
Obviously there are mentions of Python - and I can't disagree absolutely would be idiotic for anyone to argue that Python isn't a valuable good thing to put on the beginning coding list. But, if it's along the lines of coding for wifi "hacking" as an example of one discussion.....and then I see a few threads here under shell programming referring to the same local wifi.......and the target base of users is agreed upon to most likely be a majority of Windows users.....then I found myself actually arguing that Python isn't going to win you that trophy.....or could it?
Even though I'm approaching my 30yr mark in this industry, I've learned there is ALWAYS someone better and unlike some that have to always prove they are the smartest in the room, I'd much rather find that person and get schooled so that I continue to learn......
In that spirit, I looked but did not see this - I thought it could be fun to post some small ?daily? coding challenges maybe starting only in this shell programming section (but later I see no reason we couldn't include the other languages if we thought it was realistic) that would not only help those asking for starter help, but even those of us that simply want to continue to learn new solutions.
If I haven't lost you reading and you're in, I'll throw out the first one I will pick because I've not only already answered two people on this specific subject, but also this forum section recently has generated some (IMO) incredibly elaborate solutions to what I happen to know is really not that elaborate. :)
------------------------------------------------------------------------------------
Challenge:
Write the shortest most efficient code to perform the following:
1. Gather and decrypt all local Windows wifi saved credentials and output a comma separated CSV file using the following headers/data columns: "SSID", "Password"
------------------------------------------------------------------------------------
I'll post mine as a reply to this thread in a minute since I have it fresh on my mind - but I'm also going to try to add a poll to this thread if it comes through please vote as to whether you would be interested in seeing a daily coding challenge with the initial focus first on shell scripting languages wit the option to later include the more OO languages if we can find a way to maintain a realistic level of simplicity and effort so that we can see what kind of interest there is to continue it.
-Collin
Okay of all the shell languages, not only is Powershell become my favorite, but when you throw in a dotnet / Windows API background, it has become more and more powerful a shell language over the years. Coupled with it's own language version maturity, I struggle more to think of things I CANNOT do with it vs what I CAN do.....
So, no surprise this one I have seen various languages many seem to use vbscript and have made this one way to elaborate.
First of all, the big exception - this is actually one of the few cases (like I cannot remember another in years) where I find it very tough to look beyond a native cmd prompt command and not go directly to pInvoke the native C++ Windows API or use C# and a dotnet managed code call directly. But, the cmd line app by MS is really the root of most other solutions I have seen, anyway so......one line using it within my solution vs off top of my head probably 25-50+ lines of C++ or C# API calls wrapped inside my higher-level shell code calls.......
Given that I am also a huge fan of one-liners and challenging myself just how much I can accomplish in a single line of code.......I wanted to see if I could pull this one off in a single line and that removed any fancy C++ or C# native calls on this one. In fact, my first reaction was that it was not realistic anyway, but then as I really went through it in my head having accomplished it unformatted at the command-line for admin functions in the past, well.....I came around. :)
So, here is my final answer for this challenge, in a single line of Powershell code:
------------------------------------------------------------------------------------
Proposed Challenge Solution for 04/10/2017:
Submitter: @CollinChaffin
Obviously there are mentions of Python - and I can't disagree absolutely would be idiotic for anyone to argue that Python isn't a valuable good thing to put on the beginning coding list. But, if it's along the lines of coding for wifi "hacking" as an example of one discussion.....and then I see a few threads here under shell programming referring to the same local wifi.......and the target base of users is agreed upon to most likely be a majority of Windows users.....then I found myself actually arguing that Python isn't going to win you that trophy.....or could it?
Even though I'm approaching my 30yr mark in this industry, I've learned there is ALWAYS someone better and unlike some that have to always prove they are the smartest in the room, I'd much rather find that person and get schooled so that I continue to learn......
In that spirit, I looked but did not see this - I thought it could be fun to post some small ?daily? coding challenges maybe starting only in this shell programming section (but later I see no reason we couldn't include the other languages if we thought it was realistic) that would not only help those asking for starter help, but even those of us that simply want to continue to learn new solutions.
If I haven't lost you reading and you're in, I'll throw out the first one I will pick because I've not only already answered two people on this specific subject, but also this forum section recently has generated some (IMO) incredibly elaborate solutions to what I happen to know is really not that elaborate. :)
------------------------------------------------------------------------------------
Challenge:
Write the shortest most efficient code to perform the following:
1. Gather and decrypt all local Windows wifi saved credentials and output a comma separated CSV file using the following headers/data columns: "SSID", "Password"
------------------------------------------------------------------------------------
I'll post mine as a reply to this thread in a minute since I have it fresh on my mind - but I'm also going to try to add a poll to this thread if it comes through please vote as to whether you would be interested in seeing a daily coding challenge with the initial focus first on shell scripting languages wit the option to later include the more OO languages if we can find a way to maintain a realistic level of simplicity and effort so that we can see what kind of interest there is to continue it.
-Collin
(Apr 9, 2017 08:12 PM)CollinChaffin Wrote: So, I've been reading some threads from some folks just starting out in programming specific to security asking for advice on where to start.
Obviously there are mentions of Python - and I can't disagree absolutely would be idiotic for anyone to argue that Python isn't a valuable good thing to put on the beginning coding list. But, if it's along the lines of coding for wifi "hacking" as an example of one discussion.....and then I see a few threads here under shell programming referring to the same local wifi.......and the target base of users is agreed upon to most likely be a majority of Windows users.....then I found myself actually arguing that Python isn't going to win you that trophy.....or could it?
Even though I'm approaching my 30yr mark in this industry, I've learned there is ALWAYS someone better and unlike some that have to always prove they are the smartest in the room, I'd much rather find that person and get schooled so that I continue to learn......
In that spirit, I looked but did not see this - I thought it could be fun to post some small ?daily? coding challenges maybe starting only in this shell programming section (but later I see no reason we couldn't include the other languages if we thought it was realistic) that would not only help those asking for starter help, but even those of us that simply want to continue to learn new solutions.
If I haven't lost you reading and you're in, I'll throw out the first one I will pick because I've not only already answered two people on this specific subject, but also this forum section recently has generated some (IMO) incredibly elaborate solutions to what I happen to know is really not that elaborate. :)
------------------------------------------------------------------------------------
Challenge:
Write the shortest most efficient code to perform the following:
1. Gather and decrypt all local Windows wifi saved credentials and output a comma separated CSV file using the following headers/data columns: "SSID", "Password"
------------------------------------------------------------------------------------
I'll post mine as a reply to this thread in a minute since I have it fresh on my mind - but I'm also going to try to add a poll to this thread if it comes through please vote as to whether you would be interested in seeing a daily coding challenge with the initial focus first on shell scripting languages wit the option to later include the more OO languages if we can find a way to maintain a realistic level of simplicity and effort so that we can see what kind of interest there is to continue it.
-Collin
Okay of all the shell languages, not only is Powershell become my favorite, but when you throw in a dotnet / Windows API background, it has become more and more powerful a shell language over the years. Coupled with it's own language version maturity, I struggle more to think of things I CANNOT do with it vs what I CAN do.....
So, no surprise this one I have seen various languages many seem to use vbscript and have made this one way to elaborate.
First of all, the big exception - this is actually one of the few cases (like I cannot remember another in years) where I find it very tough to look beyond a native cmd prompt command and not go directly to pInvoke the native C++ Windows API or use C# and a dotnet managed code call directly. But, the cmd line app by MS is really the root of most other solutions I have seen, anyway so......one line using it within my solution vs off top of my head probably 25-50+ lines of C++ or C# API calls wrapped inside my higher-level shell code calls.......
Given that I am also a huge fan of one-liners and challenging myself just how much I can accomplish in a single line of code.......I wanted to see if I could pull this one off in a single line and that removed any fancy C++ or C# native calls on this one. In fact, my first reaction was that it was not realistic anyway, but then as I really went through it in my head having accomplished it unformatted at the command-line for admin functions in the past, well.....I came around. :)
So, here is my final answer for this challenge, in a single line of Powershell code:
------------------------------------------------------------------------------------
Proposed Challenge Solution for 04/10/2017:
Submitter: @CollinChaffin
Code
$(netsh wlan show profiles)|sls "\:(.+)$"|%{$wifiNet=$_.Matches.Groups[1].Value.Trim();$_}|%{(netsh wlan show profile name="$wifiNet" key=clear)}|sls "Key Content\W+\:(.+)$"|%{$wifiPass=$_.Matches.Groups[1].Value.Trim();$_}|%{[PSCustomObject]@{SSID=$wifiNet;PASSWORD=$wifiPass}}|export-csv -notype "Wifi_Passwords.csv"
