Sysadmin Rambling

Sysadmin Ramblings. A place to share the burden of IT

  • About

Dropbox links for Vagrant files

Posted by Syadmin Ramblings on 09/10/2017
Posted in: Scripting, Vagrant. Leave a comment

In this post I will show you how to convert dropbox links to work in the same way that public folder links worked before they where banished.

I use this for dropbox based images for my vagrant files. However it will work for embedded links in html files. Here is a video I made where I do the same thing but for vagrant box files.

 

Step 1: Get your link

https://www.dropbox.com/s/uybqelqjwpnmluc/fanta-grape.jpg?dl=0

Step 2: convert your link

https://dl.dropboxusercontent.com/s/<charactershere>/<filenamehere>
https://dl.dropboxusercontent.com/s/uybqelqjwpnmluc/fanta-grape.jpg

As you can see we break the links into 3 parts. The content provider service, the random characters you get allocated by dropbox and finally the file name.

  1. https://dl.dropboxusercontent.com/s/
  2. uybqelqjwpnmluc
  3. fanta-grape.jpg

Varnish VCL syntax high lighting in Sublime text

Posted by Syadmin Ramblings on 12/31/2015
Posted in: Uncategorized. Leave a comment

There is a plugin for VCL highlighting in sublime.

No longer shall I view hundreds of lines in plain black brick style text.

https://packagecontrol.io/packages/Varnish%20VCL

Vagrant Multi-home box files

Posted by Syadmin Ramblings on 12/31/2015
Posted in: Vagrant, Virtualization. Leave a comment

When using vagrant it is always a good idea to make the links to your box files specific so that you can get them from any computer that runs the code.
The normal place would be some form of hosted solution.

But what if you don’t really want to share your box files?

Well how about hosting your box files in the public section of dropbox?
Great that works from any computer connected to the internet.
There is a catch however…
If you use the public internet address for your box files but, the box file is on your computer in your dropbox, it will still go to the internet and download it.
Not a problem for those with 100+meg internet connection but, if you are like me and have 2 megs or are using a mobile connection where every meg is another pound of flesh then that simply won’t do.

So how can we get the best of both?

Since Vagrant files are basically just Ruby files you can do some Ruby magic in there to look for the box files.

centos_local_box = File.join(ENV['userprofile'],"Dropbox (Personal)/Public", "centos67_Base_wRuby.box").gsub!("\\", "/")
  if File.exists?(centos_local_box)
     o.vm.box_url = "file://#{centos_local_box}"
  else
     o.vm.box_url = "https://dl.dropboxusercontent.com/u/1111111/centos67_Base_wRuby.box"
  end

The code above will first make a path based on the users profile location. (This is for windows computers), then stitch it together with the rest of the arguments.
The result is a path to the box file in the public folder via local disk.
The if File.exists?(centos_local_box) will see if the file is there or if the path even exists. If true use that file, if not then use the URL in the else part.

Now this vagrant file can be used on just about any computer that I get my hands on and has vagrant installed.

Here is a video I created on the subject. It uses the new style links that drop box gives us also.

Patch KB2992611 (Winshock) breaks chrome connections

Posted by Syadmin Ramblings on 11/15/2014
Posted in: Security, Windows. Tagged: Certificates, Exploits, gotcha. Leave a comment

This page follows the discovery and remediation of the SSL Negotiation issues occuring for Chrome 38 Users after the Microsoft Patch KB2992611 (Winshock) was deployed.

The issue can be resolved by changing the list of Cipher suites offered by the server and the preferred negotiation order.
These settings are configured in the Windows registry. A tool called IISCrypto can be used to easily manipulate these settings.

The current remediation strategy is to use the ‘Best Practice’ configuration option within the IISCrypto tool.

The download and information on IISCrypto and the changes it makes can be found here:

https://www.nartac.com/products/IISCrypto/FAQ.aspx
https://www.nartac.com/blog/post/2013/04/19/IIS-Crypto-Explained.aspx

Got the time? Thanks for the bandwidth!

Posted by Syadmin Ramblings on 04/22/2014
Posted in: Cisco, Networking, Security. Tagged: Cisco, Exploits, NTP, routers, Security, switches, Vulnerabilties. Leave a comment

I was kindly notified by the internet security gods that we have some vulnerable NTP servers on our network. This came as a surprise to me as I was not aware of any internet facing NTP servers on my network. This was easily over come as the kind internet gods supplied me with an IP address of the vulnerable server. Low and be hold there it was… An internet facing NTP server.

What was it you say ? Well it was a Cisco 3750x Switch.
Why would you set up a switch as an NTP server that is internet facing with no security ? Well the simple answer is, I didn’t! It did it, itself.

Something that I only just become aware of recently is that Cisco devices will automagically become NTP servers once they have made a successful NTP association with another valid NTP server.

Why is this important ? This is why. http://www.cvedetails.com/cve/CVE-2013-5211/
This exploit allowed attackers to pump allegedly 400Gbps to a CDN service provider in a massive DDoS attack. Yes 400Gbps. Good luck getting finance to sign off a 450Gbps link to over come that.
http://www.computerworld.com/s/article/9246230/Attackers_use_NTP_reflection_in_huge_DDoS_attack

Right so how do I patch mine ?

Its surprisingly easy to fix once you get your head around the cisco documentation.

IOS router defines the following four types of access for NTP:

1) Peer – permits router to respond to NTP requests and accept NTP updates. NTP control queries are also accepted. This is the only class which allows a router to be synchronized by other devices.
2) Serve – permits router to reply to NTP requests, but rejects NTP updates (e.g. replies from a server or update packets from a peer). Control queries are also permitted.
3) Serve-only – permits router to respond to NTP requests only. Rejects attempt to synchronize local system time, and does not access control queries.
4) Query-only – only accepts NTP control queries. No response to NTP requests are sent, and no local system time synchronization with remote system is permitted.

ntp source Vlan70 # The interface that the packets will be sourced from.
ntp server 192.168.19.51 # NTP server to sync to.

ntp access-group <type> <access-list>
ntp access-group peer 1 # This is the access list that contains the NTP servers that the device will sync to
ntp access-group serve-only 2 # This access list contains the IP addresses that are allowed to query the device for time

access-list 1 permit 192.168.19.51
access-list 2 deny   any # Deny all devices that want to sync with me

Example Configuration

ntp source Vlan70
ntp access-group peer 1
ntp access-group serve-only 2
ntp server 192.168.19.51

access-list 1 permit 192.168.19.51
access-list 2 deny   any

The above configuration will allow your switch to sync with the servers in access list 1, provided that you have added them as NTP servers. It will not however respond to NTP queries from other machines (access-list 2).

Some other considerations with regards to NTP on your switches.

1) Switches translate the NTP DNS name to an IP address at boot, or when you put in the configuration. This means that should the IP address change the switch will no longer be able to sync until the next time it boots or the configuration is reset. This poses a problem when using inter based NTP servers that are out of your control. Suggestions would be to install a NTP server on something like a Raspberry Pi and tell it to rather sync to an internet based NTP server. Then have your switches sync to that device. The NTP service under linux is much more configurable than the switches. Also the pi can be powered by the USB port on the switches.

2) Switches will not sync with stratum 1 devices by default. Stratum 1 devices are devices that believe and report that they are time lords. They do not sync to other devices. These legitimately include atomic clocks and GPS devices that sync with satellites. The switch will check if the peering partner has in fact synced to another server before it will accept it as a time source.

3) Peering takes long! NTP IS SLOW! It may be all about time but its is slower than paint drying!
I have seen NTP take will over 15 minutes to sync to a known working NTP server. Debug messages and slow brewed coffee are your friends here!

Lastly a thought that brought all of this to light.
As quoted from Matthew Prince, CEO, who said that it’s “the start of ugly things to come” because “someone’s got a big, new cannon.”

The internet was invented for EVERYONE. I’m sure it was not invented to be a weapon!

The myth of the Created date stamp.

Posted by Syadmin Ramblings on 03/30/2014
Posted in: Linux, Powershell, Scripting, Windows. Tagged: Date stamps, dates, scritpting, Windows. Leave a comment

Want a script to delete files that are older than a certain date? Lets say more then 30 days old.
Your mind first races to the created date stamp. Well you may need to think that over in some situations!

Lets take a look at some date stamps in Windows. Then I’ll explain.

image

This file was last modified over a month before it was created !!!!

No its not photoshop or dark sysadmin scripting or even magic computer time travel!
Its actually a lot simpler than that. Simply it was copied. But it does put you in a peculiar situation.

When do we consider the file to be created? The moment it was conceived or the moment it arrived on this disk. Here’s an even better mind twister.
Consider that you have a script that copies files from file shares to a central repository and then deletes files older than say 30 days. Well the files would be greater than 30 days old before they get deleted. Since the dates created date would be the date that the file was copied to the disk. This is if you only copy the file once.

There is no simple solution to this one, but its worth keeping in mind the next time that you want to write a script.

I sometimes like to make use of time stamps in the names. These should never change in automated systems.

Running an exe in PowerShell

Posted by Syadmin Ramblings on 03/30/2014
Posted in: Powershell, Windows. Tagged: Pwersehll, run exe, start-process, windows scripts. Leave a comment

PowerShell allows you to execute exe files in 2 different ways. The easy way and the proper way.

The Easy Way:

The easy way to execute an exe with arguments is to just use the & symbol before the commands.

& c:\proc\my.exe –i –j –k c:\userdata

The issue with this is it will fire up in a different window and you will have no control over it. Which is ok for somethings but not for many MANY others.

The Proper Way:

So the solution is to use start-process instead. Start process gives you lots of extra control over the working process. Things such as the output, input, error control, PID, Status, etc….

I often us this cmdlet with the following keys, –wait and –NoNewWindow. These 2 combined give me the ability to have my code wait till this process is complete before processing further.

$exe = “c:\proc\my.exe”
$args = “–i –j –k c:\userdata”
start-process –filepath $exe –Arguments $args –wait –NoNewWindow

You have to also give the cmdlet the file path to the executable file in a variable and then a separate variable with the arguments of the executable as strings.

Have a look at: http://ss64.com/ps/start-process.html for further details.

Arrays adding and removing objects

Posted by Syadmin Ramblings on 03/29/2014
Posted in: Powershell, Windows. Tagged: arrays, Powershell, Windows. Leave a comment

It may seem like a simple post but it took me a bit to figure out.

Powershell in my mind works with arrays in the most inefficient way possible.
It seems to say its an array but its kind of a sting with comma separated values in the back. In this light working with arrays can be rather cumbersome and it just plain looks stupid.

Lets start with an empty array.
$var1 = @()

Now lets add something to the array. This is easy and “looks” right.
$var1 += user1
$var1 += user2

So now we have:
$var1 –eq (user1, user2)

Now lets remove user1. From the above syntax you would expect it to be something like.
$var1 –= user1
But that’s not right. In fact you need to make powershell create a whole new array but with out the part you want.

$var1 = $var1 |? {$_ –ne user1}

Is it just me or does this just look plain wrong, dirty and long winded ?
Really, equal to yourself where object is not equal to given value. REALLY!
Consider the processing overhead when you have an array with thousands of objects. REALLY!
Maybe the wizards at M$ will come round to sorting that out someday but until then that’s how to get it done.

In Powershell we tell you what variable you are!

Posted by Syadmin Ramblings on 03/29/2014
Posted in: Powershell, Windows. Tagged: arrays, gotcha, Powershell, stings, variables. Leave a comment

Powershell’s ability to decipher what a variable is based on its contents is both a blessing and a curse. Here is another gothca that will leave you thinking what the hell is going on.

Consider this.

$var1=(get-childitems –path c:\users)
foreach ($child in $var1)
{ if ($var1 –ne “admin”)
     { $var1 = $var1 |? {$_ –ne $child}}
}

Eventually this $var1 is going to only have 1 array object in it. “admin”. This is where you need to factor in powershells sometimes strange behaviour. Let add some more code now.

$var1 += user2

At this point your expecting that the values that you’ll have would be an array containing
{admin, user2}
But you’d be wrong. You will in fact have a string that contains but admins smoshed together.
var1 = adminuser2
If you where counting on it being an array and used say the ().count key then you would get an odd value of 10 and not the expected 2.

So what’s the solution?
Use strong typing. In other words TELL Powershell EXACTLY what you want.

Start off with
var1 = @(get-childitems)
or even better if you can declare it at the beginning of the script.
var1 = @()
Then after start adding and removing object from this array.

Although its not all bad. Most the time Powershell gets this right.

PowerShell – Start-Process: The hidden nuke!

Posted by Syadmin Ramblings on 03/28/2014
Posted in: Powershell, Windows. Tagged: error handling, Powershell, scripting, start-process. Leave a comment

PowerShell has a way with defiance that is rarely even seen in the most stubborn teenagers.
Here is another gotcha that I ran across recently.

This gotcha is part of the “Start-process” cmdlet and is being witnessed in version 4.0

Here’s the brief: start-process is being used to execute a tshark.exe process. However the tshark process is exiting out with an error about a packet being only half captured. This error has got to do with the laziness that is dumpcap.exe. But since I’m expecting this to happen i would like to just carry on with the next line of code.

Here’s a code snip-it to put in context the above

$tsharkdir = “C:\Program Files\Wireshark\tshark.exe”
$tspara = “-r C:\test\trace\d1\captures\cap1.pcap -Y sip -w C:\test\trace\d1\processing\out.pcap”

write-host “before”
Start-Process -FilePath $tsharkdir -NoNewWindow -wait -ArgumentList $tspara
Write-Host “after”

So whats the issue you say?
-NoNewWindow should in fact redirect the output from the “console” that the process will run in. However in this instance it just doesn’t. Instead it just shows nothing.

Well then just continue if there is an error with –ErrorAction Continue. Well that would help if powershell would simply listen to that argument.

What happens ? The start-process will cause the script to die in a horrible nuclear explosion that will destroy your computer. Well actually it will just cause the script to stop at that point.

So what’s the solution … First we need to consider what’s happening. We simply need that output. But how do we get it. –RedirectStandardError error.txt. The here is the magic.

It seems that powershell is having a problem with the error text and not actually the error itself. So if I tell it to redirect the error to this magic file (which gets overwritten each time there is an error so it will never get very large. we’re talking KB here) everything then works. consider the text the nuke. discard the nuke and live happily ever after. Now powershell does have to handle this error text anymore its happy to listen to the –ErrorAction

Here is the solution in code.

$tsharkdir = “C:\Program Files\Wireshark\tshark.exe”
$tspara = “-r C:\test\teltrace\d1\captures\cap1.pcap -Y sip -w C:\test\teltrace\d1\processing\out.pcap”

write-host “before”
Start-Process -FilePath $tsharkdir -NoNewWindow -wait -ArgumentList $tspara -RedirectStandardError error.txt -RedirectStandardOutput out.txt -ErrorAction Continue
Write-Host “after”

Posts navigation

← Older Entries
  • Recent Posts

    • Dropbox links for Vagrant files
    • Varnish VCL syntax high lighting in Sublime text
    • Vagrant Multi-home box files
    • Patch KB2992611 (Winshock) breaks chrome connections
    • Got the time? Thanks for the bandwidth!
  • Archives

    • September 2017
    • December 2015
    • November 2014
    • April 2014
    • March 2014
    • October 2013
    • August 2013
    • July 2013
    • May 2013
    • March 2013
    • December 2012
    • November 2012
    • October 2012
  • Categories

    • AV
    • Cisco
    • Exchange 2010
    • HyperV
    • Linux
    • Networking
    • Powershell
    • Scripting
    • Security
    • Server 2012
    • Sonicwall
    • Uncategorized
    • Vagrant
    • Virtualization
    • VMWare
    • Windows
  • Meta

    • Create account
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.com
Blog at WordPress.com.
Sysadmin Rambling
Blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
    Sysadmin Rambling

    Have a WordPress.com account? Log in now.

  • Sysadmin Rambling
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar
Loading Comments...
Create your own website, free on WordPress.com.Create your own website.
Start free