The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,854 other subscribers

Archive for the ‘Scripting’ Category

Powershell links (via: Scott Hanselmans 2011 Ultimate Developer and Power Users Tool List for Windows)

Posted by jpluimers on 2012/04/06

If you like .NET and scripting, then PowerShell and the PowerShell Community Extensions is what you should try:

PowerShell – The full power of .NET, WMI and COM all from a command line. PowerShell has a steep learning curve, much like the tango, but oh, my, when you really start dancing…woof. I also use PowerShell Prompt Here. Its built into Windows 7, by the way.

  • I also recommend after installing PowerShell that you immediately go get PowerTab to enable amazing “ANSI-art” style command-line tab completion.
  • Next, go get the PowerShell Community Extensions to add dozens of useful commands to PowerShell.
  • Want a more advanced GUI for PowerShell? Get the free PowerGUI.

Thanks Scott for summarizing :)

–jeroen

via: Scott Hanselmans 2011 Ultimate Developer and Power Users Tool List for Windows – Scott Hanselman.

Posted in .NET, Development, Power User, PowerShell, Scripting, Software Development | 1 Comment »

The “San Seriffe” of PHP: “PEP 313 — Adding Roman Numeral Literals to Python”

Posted by jpluimers on 2012/04/01

At 9 years of age, PEP 313 still is a classic april fools joke. One of the hilarious parts:

This PEP is rejected. While the majority of Python users deemed this to be a nice-to-have feature, the community was unable to reach a consensus on whether nine should be represented as IX, the modern form, or VIIII, the classic form. Likewise, no agreement was reached on whether MXM or MCMXC would be considered a well-formed representation of 1990. A vocal minority of users has also requested support for lower-cased numerals for use in (i) powerpoint slides, (ii) academic work, and (iii) Perl documentation.

–jeroen (who also loves the San Seriffe joke of 1997)

via: PEP 313 — Adding Roman Numeral Literals to Python.

Posted in Development, Opinions, PHP, Scripting, Software Development | 1 Comment »

Some PowerShell SCCM links

Posted by jpluimers on 2012/03/22

http://www.powershell.nu/2010/10/07/powershell-sccm-client/

http://www.powershell.nu/tag/sccm-2007/

 

http://devinfra-us.blogspot.com/2008/04/sccm-and-powershell-part-1.html

http://devinfra-us.blogspot.com/2008/04/sccm-and-powershell-part-2.html

 

http://thepowershellguy.com/blogs/posh/archive/2008/05/16/sccm-and-powershell-series-using-my-powershell-wmi-explorer.aspx

http://thepowershellguy.com/blogs/posh/archive/tags/WMI+Explorer/default.aspx

http://thepowershellguy.com/blogs/posh/archive/2007/03/22/powershell-wmi-explorer-part-1.aspx

 

http://tfl09.blogspot.com/2010/03/sccm-powershell-module.html

 

http://www.snowland.se/2010/03/10/sccm-module-for-powershell/

http://www.snowland.se/sccm-posh/

 

Posted in .NET, PowerShell, Scripting, Software Development | Leave a Comment »

Enabling powershell to run unsigned scripts for the current user only (via: Absoblogginlutely!)

Posted by jpluimers on 2012/03/21

More than a year ago, I wrote about enabling PowerShell to run unsigned scripts, and a way to circumvent the “cannot be loaded because the execution of scripts is disabled on this system” error.

The solution  there uses the Set-ExecutionPolicy cmdlet, but only works for administrators. As of PowerShell 2.0, there is more fine grained control for the Set-ExecutionPolicy cmdlet, and an updated Set-ExecutionPolicy cmdlet topic which I overlooked.

The solution below shows what happens when the current user is not an administrator, and works around it by applying it only for the current user.

error message:

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.

Sure enough I don’t have permission to this registry key.

I checked with our admin to ensure this wasn’t set in group policy before I started fiddling around. Found out that there is another setting that is user specific that can be set with

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

This will allow the current user to run unsigned scripts he wrote himself, but still require remote (for instance downloaded) scripts to be signed.

Note it is easy to strip the “remote” flag of a downloaded script: NTFS keeps this flag in the Zone:Identifier NTFS alternate data stream.
Only do that for scripts you trust.

–jeroen

via: Absoblogginlutely! » Enabling powershell to run scripts with registry permissions..

Posted in .NET, Development, PowerShell, Scripting, Software Development | 4 Comments »

Batch file to detect Windows version number

Posted by jpluimers on 2012/02/08

Most Batch files for detecting Windows versions try to parse the either the [WayBack] output fromVER  or the [WayBackoutput from SYSTEMINFO [WayBack], but forget that there many Windows installations are not English. Some even use WMIC, but [WayBackWMIC is only available for administrators and not available some flavours like XP Home.

Languages issues are always important to watch for. The Dutch Windows XP returns Microsoft Windows XP [versie 5.1.2600] which is just one word different from the English Microsoft Windows XP [Version 5.1.2600]. Other languages may differ even more.

This batch file tries to circumvent the language differences, uses VER and works at least with Dutch and English Windows versions of XP and 7, most likely with many other languages and versions as well.

On a Windows XP SP3 machine, it lists WindowsVersion=5.1.2600 and on a Windows 7 SP1 machine it lists WindowsVersion=6.1.7601.

One possible addition would be to [WayBack] detect x64 or x86.

The detection assumes that VER will emit the version in [angle] brackets, and uses two batch file for loops to get the text in between them using the [WayBacktokens and delims for loop parameters in the first for loop right behind the begin label and the second for loop right after the parse1 label.

Then it splits the remaining text using spaces at the parse2 label, and takes the right most portion using the [WayBackshift command at the parse3 label.

Many thanks to [WayBackRob van der Woude for a lot of interesting batch file documentation. Read the rest of this entry »

Posted in Batch-Files, Power User, Scripting, Software Development, Windows, Windows 7, Windows XP | Leave a Comment »

Outlook signature locations

Posted by jpluimers on 2012/02/07

When Google searching, most results for the Outlook 2003 Signature Folder Location AppData give you the wrong folder.

They mix environment keys like UserName, UserProfile, but should use AppData as that has been the base since at least Windows XP.

This is the correct folder for any Outlook version (2003, 2010, etc): %appdata%\Microsoft\Signatures

Making sure you use the right environment variable is very important, especially in large Windows based environments that often use roaming profiles and a mix of Windows environments.

For instance, at a client they have a mixed environment of Windows XP and Windows 7, with separate AppData locations for the two on a LAN:

  • Windows XP:
    \\server\DFS\share\Application Data
  • Windows 7:
    \\server\DFS\share\Application Data.v2

There is a very nice Wikipedia article on the Windows Environment variable that explains this situation in the synopsis.

–jeroen

Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows, Windows 7, Windows Vista, Windows XP | Leave a Comment »

Batch file examples – Wait using CHOICE (via: RobVanDerWoude.com)

Posted by jpluimers on 2012/01/19

Most batchfile wait examples require a functioning network connection.

Just in case you haven’t, Rob van der Woude has a nice example on his batch file Wait page using the Choice command.

The bummer is: choice is available on almost all Windows versions (actually since DOS 6.x), but not on Windows XP, and not on Windows 2000, but it is there in Windows Vista and up where you can use the timeout command :(

Alternatives can be found in the other examples on Rob’s wait page.

CHOICE – Wait.bat: Uses CHOICE to wait for a specified number of seconds.

By using REM | before the CHOICE command, the standard input to CHOICE is blocked, so the only “way out” for CHOICE is the time-out specified by the /T parameter.

The idea was borrowed from Laurence Soucy, I added the /C parameter to make it language independent.

@ECHO OFF
IF "%1"=="" GOTO Syntax
ECHO.
ECHO Waiting %1 seconds
ECHO.
REM | CHOICE /C:AB /T:A,%1 > NUL
IF ERRORLEVEL 255 ECHO Invalid parameter
IF ERRORLEVEL 255 GOTO Syntax
GOTO End
:Syntax
ECHO.
ECHO WAIT for a specified number of seconds
ECHO.
ECHO Usage: WAIT n
ECHO.
ECHO Where: n = the number of seconds to wait (1 to 99)
ECHO.
:End

–jeroen

via: Batch file examples – Wait.

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Dear Mister Jones » How to insert a carriage return with batch

Posted by jpluimers on 2012/01/17

When appending multiple text files to a big one (for instance to post-processing on the total: dedupe, sort, gather statistics, etc) you often will find one or more of the source files missing a CRLF.

So you will have to insert those carriage return line feed combo’s manually.

Well, mr Jones points out that:

there’s actually an easy way to simply echo a carriage return and line feed instead, by just issuing an echo command followed immediately by a period (no space in between), like this:

echo. >> somefile.txt

Thanks Jared!

–jeroen

via: Dear Mister Jones » How to insert a carriage return with batch.

Posted in Batch-Files, Development, Scripting | Leave a Comment »

Should watch: Dave Herman: The Future of JavaScript #ECMAScript6

Posted by jpluimers on 2012/01/11

On:

Mozilla Labs engineer and TC39 representative Dave Herman joined us at YUIConf 2011 to give this keynote talk on the future of JavaScript, covering many of the new features currently under consideration for ES6, the next edition of the ECMAScript standard.

Many wonderful new features. Now it just need some great tooling.

–jeroen

via: http://www.youtube.com/watch?v=u4IdoBU1uKE

Posted in Development, JavaScript/ECMAScript, Scripting, Software Development | Leave a Comment »

Many more web platforms vulnerable to the hash collision attack (not only ASP.NET) #28C3 @hashDoS #hashDoS @ccc

Posted by jpluimers on 2011/12/29

When writing my Patch your ASP.NET servers ASAP early this morning, I didn’t have time to research the full extend of the vulnerabilities published at 28C3 (slides, mp4), though a small bell was ringing a message that I had seen something like it before earlier this century.

I was right, this posting on perlmonks direct me to a /. posting in 2003 pointing me to the research paper on low-bandwidth attacks based on hash collisions (pdf version) that I had seen before. Perl 5.8.1 fixed it September 2003 (search for “hash” in that link).

The attack can be used for DoS because a normal distributed hash table insert of n elements will be running O(n), but a carefully crafted insert of those elements will run O(n^2).

Carefully crafting a worst case scenario depends on how well you can predict collisions in the underlying hash table implementation, which – apparently – is not too difficult, and requires little bandwidth.

Many platforms and languages are vulnerable (already archived at the WayBack machine), including those based on Java, Tomcat, .NET, Ruby, PHP and more in greater or lesser extent. I have the impression that the list only includes big names, but presume platforms based on smaller names (ASP, Delphi, Objective C) are equally vulnerable.

Just read the articles on CERT 903934, oCERT 2011-003Arstechnica, Cryptanalysis.euHeise (German), Hackillusion and the research paper published at 28C3.

a few quotes:

“This attack is mostly independent of the underlying Web application and just relies on a common fact of how Web application servers typically work,” the team wrote, noting that such attacks would force Web application servers “to use 99% of CPU for several minutes to hours for a single HTTP request.”

“Prior to going public, Klink and Wälde contacted vendors and developer groups such as PHP, Oracle, Python, Ruby, Google, and Microsoft. The researchers noted that the Ruby security team and Tomcat have already released fixes, and that “Oracle has decided there is nothing that needs to be fixed within Java itself, but will release an updated version of Glassfish in a future CPU (critical patch update).”

“The algorithmic complexity of inserting n elements into the
table then goes to O(n**2), making it possible to exhaust hours of CPU time using a single HTTP request”

“We show that PHP 5, Java, ASP.NET as well as v8 are fully vulnerable to this issue and PHP 4,
Python and Ruby are partially vulnerable, depending on version or whether the server
running the code is a 32 bit or 64 bit machine.”

Microsoft seems to have been notified pretty late in the cycle, I presume because the researchers started with a some platforms and finally realized the breath of platforms involved.

The ultimate solution is to patch/fix the platforms using for instance a randomized hash function a.k.a. universal hashing.

Microsoft will provide a patch for ASP.NET later today, Ruby already patched and other vendors will soon or have already (please comment if you know of other platforms and patches).

The links this morning indicated there were no known attacks. That is (maybe was) true for ASP.NET, but for PHP a public proof of concept of such a DoS is has been published by Krzysztof Kotowicz (blog) with sources at github and a demo html page.

Temporary workarounds (based on the some of the links in this and the prior blog post, and the workarounds mentioned here and here):

  1. If you can: replace hash tables by more applicable data structures
    (I know this falls in the for-if anti-pattern category, but lots of people still use a hammer when a different tool works much better)
  2. Limit the request size
  3. Limit the maximum number of entries in the hash table
  4. Limit form requests only for sites/servers/etc that need it.
  5. Limit the CPU time that a request can use
  6. Filter out requests with large number of form entries

Some platforms already have applied temporary workarounds (I know of Tomcat (default max 10000 parameters), and PHP (default max_input_vars = 1000) did, and looks like the ASP.NET fix will do too).

Other platforms (like JRuby 1.6.5.1, CRuby 1.8.7 (comments) and Perl 5.8.1 in September 2003 ) fixed it the proper way.

Note: workarounds are temporary measures that will also deny legitimate requests. The only solution is to apply a fix or patch.

A major lesson learned today for a few people around me: when vendors start publishing “out of band” updates, do not trust a single 3rd party assessment with state “initial investigation”, but be diligent and do some further research.

–jeroen

PS: Just found out that most Azure users won’t need to manually apply a fix: just make sure your Hosted Service OS servicing policy is set to “Auto”.

Posted in .NET, ASP.NET, C#, Cloud Development, Delphi, Development, Java, PHP, Ruby, Scripting, Software Development, Web Development, Windows Azure | 6 Comments »