Monday, February 23, 2015

Linux/Windows/Mac and Opinion

I will try to not be exclusive in the future with the how to's etc. If someone really needs me to convert something I have written to a different OS ask. I have comments open for a reason and will do my best, or feel free to email me. The rest of this post is kinda rant like so feel free to skip it.

So I am a windows user and have been for an extremely long time, but mostly by culture not by choice. Essentially Windows was chosen for me many times and I've just gone with it. I have looked at Apple and played with it a bit but in all honesty I am starting to fall in love with Linux distros.

1) They are FREE 99
2) They come with the things you need when working as an admin.
3) Updates are much easier to handle and control I feel.

Reasons why I will ALWAYS own a windows machine (or VM):
1) Gaming - people don't develop games as much for linux
2) Excel - It is the most robust tool for any financial things and although I am not an expert with it (nor an accountant) I get files that are in Excel format and can't always change/convert.

So From what I have found it comes down to why are you using the machine. I have something like 5 or 6 (or maybe closer to 10) computers in my house and I use each for different reasons. In working as an Administrator I have found you pretty much have to use Linux at some point and so I am learning what I can replace on Windows with Linux alternatives and for somethings it is just easier for me to do in Windows because I have done it that way for so long.
So I guess I am going to re-install some of my computers with Linux.

I decided to comment on Mac as well. I own a really really old (over 10 years) MacBook but I'm a poor guy so I am not able to speculate on Mac. Nor will I include any mac stuff in my how to's as I can't test it.

Thursday, February 19, 2015

Task oriented

I am a very task oriented person.
Pen and paper works best for me. something about hand writing it helps me.

other options:
Evernote:
I was not a big fan of, mostly because writing it down kept me more focused. It does allow you to do many more things though so if you are a good note taker and have lots of notes this is a nice application.
I stole the image from Google (I think it actually came from the evernote blog).

Google tasks:
https://mail.google.com/tasks/canvas
Lets you have multiple lists. I use this one for goals for myself rather than actual tasks.
Your phone task list - I never got this one down but for some people it is a quick task list they need.

Another one that I have used is Asana.
This is a nice way for a manager to assign tasks as well as it makes it easy to break things down to different levels and make projects. This was very nice for me when my tasks changed daily on what I needed to work on as my manager could see what I was doing and assign things different priorities. The best part about it is the hidden unicorn feature.


Same thing for this image as the Evernote one.

Wednesday, February 18, 2015

Microsoft Security Essentials Logs

So there may come a time when you need to know what has happened with your virus scans for reporting or anything really (for me it was reporting). Well when that happens here is how you can find your logs in Microsoft Security Essentials.

Microsoft Security Essentials (MSE) actually logs all of its scans and findings, although you can't find them in the program itself. It logs them to the event viewer.
There are a couple of options:
1) Find and create a filter for the specific logging you want.
2) There is a built in dump of all of the logs to one file called MpCmdRun

To run the built in option simply open an administrator command prompt and go to the directory where it is located. 

cd %programfiles%\Microsoft Security Essential
[add pic]
Then run "MpCmdRun.exe -getfiles"

It takes a bit to run sometimes depending on how often and how many logs there are.
It makes a file called MPSupportFiles.cab which will be saved automatically to "%ProgramData%\Microsoft\Microsoft Antimalware\Support\" folder
[add pic]

The other option lets you export an XML so you can then import that into MySQL or anything really. I will get a query once I test it out again.

You can also use the Event Viewer (Start > Run > eventvwr.msc) under [System] right click View > filter (by Event Source: Microsoft Antimalware) 
I usually make the filter for a week so I don't get too much data.

I filter out the update events but other than that here is the xml:
<ViewerConfig><QueryConfig><QueryParams><Simple><BySource>True</BySource><Channel>System</Channel><Source>Microsoft Antimalware</Source><RelativeTimeInfo>4</RelativeTimeInfo><EventId>-2000</EventId></Simple></QueryParams><QueryNode><Name>MSE Events</Name><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='Microsoft Antimalware'] and TimeCreated[timediff(@SystemTime) &lt;= 604800000]]]</Select><Suppress Path="System">*[System[(EventID=2000)]]</Suppress></Query></QueryList></QueryNode></QueryConfig></ViewerConfig>

It is all in one line. To export it to a database it is easier to use powershell but that was a project in and of itself so I am not going to go over that in this post.

Monday, February 9, 2015

How to reduce the root partition in LVM


So at work I ended up being told two different things. First I was told use all of the disk space so that we can get an LVM with as much size on it as possible. Then I was told oh we need 20 percent or so so that we can use it for backing up. With that I set out on a mission to find out how to resize LVM space. We come to find out we put the root partition in the LVM. This means we have a few more steps to do.

A few sites mention how to do this but I found one step by step guide with pictures the rest were not as informative as this site and we were using the same distro so I chose to use this for my base documentation. Other changes include a few grammer tweaks.

Best practice would be to make sure you don't have to shrink your LVM as it can become corrupt, and it is much easier to enlarge it.

Modified from:

https://rbgeek.wordpress.com/2013/02/11/how-to-reduce-the-root-partition-in-lvm/

My additions are in blue comments and have brackets
In this tutorial, I am using the CentOS 6 (I believe that its also applicable on other Linux distro but haven't tried yet) that has ext4 partition lv_root mounted as / and lv_swap as swap from the volume group vg_centos6 (which is default), that has two hard drives (66GB & 25GB). Due to some reasons, I want to remove the 25GB hard drive from my computer and want to add new 50 GB hard drive. Before, removing the hard drive from the computer, we need to resize the lv_root, then remove it from volume group and at the end from the physical volume.

WARNING: It’s really dangerous, so backup your data before attempting this. Please don’t blame me, if you destroy your system. You are responsible for your own actions!

Check the size of lv_root before starting this process:
df -h



Boot from CentOS 6 DVD (or any other Linux distro that you are using) and select “rescue” option:



[The next thing I chose to do was I selected to enable the em0 (the ethernet device adapter) incase I needed it for any reason. This was not a step mentioned in the tutorial I took this from.]

Select the Skip, so that it will not mount the filesystem:



Run these commands:

pvscan
vgscan
vgchange -a y
lvscan



Display the lv_root:

lvdisplay /dev/vg_centos6/lv_root



[This section would not run] fsck on the large root filesystem (lv_root):

fsck.ext4 /dev/vg_centos6/lv_root

]

Run e2fsck with -f (force) option:

e2fsck -f /dev/vg_centos6/lv_root



Issue the resize2fs command to reduce the filesystem (Important: The size here is the actual/total size of thelv_root after reduce, not the size that we want to decrease):

resize2fs -p /dev/vg_centos6/lv_root 65G [I chose to use 2750G as we have 4 terabytes and that is what I calculated to be 20 % ish]



Now, issue the lvreduce command to reduce the logical volume size:

lvreduce -L 65G /dev/vg_centos6/lv_root [Once again I chose to use 2750G]



Run lvdisplay command to confirm the change:

lvdisplay /dev/vg_centos6/lv_root



Reboot the system and login. Remove the disk (in my case it is, /dev/sdb1) from volume group and then from physical volume:

[These next two commands would also not run]

sudo vgreduce vg_centos6 /dev/sdb1

sudo pvremove /dev/sdb1

]

Check the size of lv_root after all these changes:

df -h



Success!

Monday, January 26, 2015

Netstat, ports and taskkill

The netstat command in windows I found very useful for identifying problems with Apache not running. Most of the time I found the actual problem was that something else had already bonded on port 80.
Simply run netstat -ano in the command line (as an administrator of course) and end the process that is causing the hiccup. be warned sometimes this is a system process. You may want to find out more about the process first using the task manager and good old fashioned google searching.

For more info on how to do any of this visit:
http://security.fnal.gov/handouts/IdentifyingOpenPortsWinXP-2003.pdf

Taskkill
The taskkill command is nice if you have a task that just will not close or you opened up a billion of the same thing and you only have a remote connection you don't want to loose. There are other uses for it but I have mostly used it for those things.
If you know the PID (which you can get using the task manager or the aforementioned netstat) or the imagename (which you can use if it is multiple instances of the same)
taskkill /IM imagename /T /F
or
taskkill /PID processid /T /F
The /T kills and child processes which were started by it and the /F forcefully terminates it

Monday, January 12, 2015

PHP and SQL


So I used to use these daily (MySQL more than anything and PHP mostly I just looked at and told the dev team it looks like your bug is around here so reading more than writing) and there were a few things I had to look up every time because I'm forgetful. Before I start posting a bunch of other Random Tech Info I wanted a post for my original reason for making the blog! Unfortunately I have less use of it now but for anyone else who may need it here it is!

PHP
Time Zones I commonly needed:
America/Denver
America/Los_Angeles
America/New_York
Full list is available here:

http://php.net/manual/en/timezones.america.php

Error Reporting:
Nothing is more frustrating than bad code, except bad code that doesn't load because of a WAMP errorloging:
[add pic of file here]
Change E_ALL to E_ERROR in the php.ini file. In my opinion the only time a production server should report all errors is in testing or when troubleshooting. Otherwise you are using resources that can be used elsewhere in production.

Other types of "Bad code"
Bad code isn't just code with bugs in it. It is also code that is written that is hard to understand, or code that is written so complicated that it takes forever to run.
Sometimes though it is not as easy as simply "fixing" the code as it is changing the way things are done (for example calculating a number every time versus storing the number in the database once it is calculated and then checking to see if it needs recalculating because other numbers have changed or not because nothing has changed).

Long store short, Sometimes this is needed:
max_execution_time = 300
that is 5 minutes. I don't recommend going higher ever as (from what I have heard) other vulnerabilities may exist and that gives hackers a 5 minute window in that area.

MySQL
Max Allowed Packets-
Most commonly used when restoring large databases (I think the WAMP build was way outdated).
Packets larger than max_allowed_packet are not allowed.
The max_allowed_packet variable can be set globally by running a query.
However, if you do not change it in the my.ini file (as dragon112 suggested), the value will reset when the server restarts, even if you set it globally.
To change the setting for everyone until the server restarts:
SET GLOBAL max_allowed_packet=1073741824;
OR
Change in the my.ini file. Include the single line under [mysqld] in your file
max_allowed_packet=500M
now restart the MySQL service and you are done.
[add pic of file]
http://opensource-soa.blogspot.com/2008/08/change-mysql-maxallowedpacket-variable.html

Creating a TEMP table
CREATE TEMPORARY TABLE IF NOT EXISTS table2 AS (SELECT * FROM table1)
You can get much more in-depth with selecting different columns etc.

Creating table from scratch with unique id's in sequential order to insert data manually
I hated doing this as it involved a lot of hand work until I learned how to do it this way.
SELECT  column1,
        column2,
        column3,
        @curRow := @curRow + 1 AS row_number
FROM    table
JOIN    (SELECT @curRow := 0) r;

Intervals are very useful so you can find things that are most recent or in a certain date range:
SELECT * FROM table
WHERE datetime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW();

For SQL Server Identity Insert:
SET IDENTITY_INSERT IdentityTable ON
INSERT IdentityTable(TheIdentity, TheValue) VALUES (3, 'First Row')
SET IDENTITY_INSERT IdentityTable OFF

Using Variables
I didn't have to do this a lot but I had to look it up every time. Essential I had to create a table using information from other tables (if you ever have to do this I am sorry, consult your programmer about just grabbing the information he needs from the places it actually exists... and don't let him BS you he can make it work). I had to make unique ID's for a table and this was the simplest way I could find. Let me know if someone has a better.
First declare your variable.
DECLARE @i AS int;
Then set it to a starting point:
SET @i= 0;
Then your select query:
SELECT @i+1, column1, column2 FROM table1 JOIN table2 on table1.columnA = table2.columnB WHERE columnC = (something);

Monday, December 29, 2014

Cisco

So it has been a while and I am sorry to anyone who actually reads this. Recently I have moved twice and gotten a new job, hence the lack of posting. I decided last week I would make a post about some Cisco things that I have learned.

If you are like me and don't feel like going through the hassle of java certificates etc and you have a spare windows machine laying around, install java 6 update 43 on it. So long as you don't plan on running anything else you are fine. If you really want to be sure put it in a VM. Then you can destroy it if need be.


Java 6 is in my one drive if anyone needs it (I have both linux and windows versions). And because I know I am going to forget how to do this on linux:
http://www.oracle.com/technetwork/java/javase/install-linux-64-self-extracting-142068.html

1) It is just easier to learn it in the command line. I have gone through the ASDM* set ups and they are nice for doing basic things but when it gets down and dirty, the command line interface is how you fix any mistake you made, and i made quite a few.

*If you like the ASDM option don't forget the first thing you need to do in order to get it to load is create a user, Cisco gives help on the matter but I'll make it simple, for an admin user with all privileges in the command line first enable command then config (should go from > prompt to # then to (config)#): username myusername password donttellanyonethis privilege 15. Users range from 1 to 15. 15 is the Highest
[add pic]

2) Active/Standby Fail over and a non managed switched- I did quite a bit of ready on the fail over as no one in my new company new anything about it. My big thing that I found out is that Cisco recommends connecting to the devices through a switch (a managed switch I later found out). Cisco's ready is very heavy if you don't know what you are doing so forums and blogs like http://www.petenetlive.com/ have been the only reason I even got as far as I did. I went from knowing little to enough to get into trouble (that's where I am still at). If you aren't using a managed switch the two devices sometimes have trouble finding each other and it is easier to simply plug them into each other directly so they can talk (ASDM defaults to port 7 so in a server rack side by side it gets kinda odd for the 5505's which is what I have been working with).

3) A couple don'ts- Don't forget to back everything up (depending on your environment every change you make should be backed up). Don't forget to save to Flash (I may have made it so everyone had a user but as soon as I unplugged the router to take it to the DC I was the only one with a user). Save to flash is at the bottom and looks like a floppy drive. Also don't forget to hit apply BEFORE you hit save to flash.


4) Lastly another reason to backup - So I actually found that the backup files are stored as text files. Quite a bit of what I have been configuring needs to be reproduced on other systems. I found it can be stored and it is just the commands that ASDM runs, which are just the terminal commands. With a basic understanding you can take a backup and apply it to another device which is quite nice.

That's it for today. I am currently in the process of actually learning Cisco so I can get my certifications as well as Linux much better than before as I know use each daily. Also somehow I got put in charge of a program implementation called SaltStack for our servers. It is a server management tool so I will have future posts about it (this is to remind me) as I currently know little about it.