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.

Sunday, June 1, 2014

AutoIt

AutoIt is a great and simple tool for windows. I've found it makes it a ton easier to automate things. Even if you want to run batch or power shell scripts. Recently I've even used it to do Bing reward searches for me (as I prefer to use google still). I'll upload my code in a future post. 

Thursday, December 26, 2013

Adware

Be ware of the ever present adware in everything you download. While you don't have to read the end user agreement, make sure you are not agreeing to more than one. My wife or my Brother one download some adware to my laptop (which I rarely use). It was a pain to get rid of but I finally managed it and found out a few things in the process.

First I found a program called adwcleaner. This program is fairly nice. Not that I'm trying to convince anyone, but my work buddy used malware bytes and couldnt get rid of it. This did. Also note that this is a FREE software, if you got one that asks for payment it is an adware program.

After I ran this I found a few other adware programs that were installed and set to boot up. It was giving me a hard time so I tried using this tool called jrt (junkware removal tool). After that didn't get rid of everything I played with windows for a bit.

I found malwarebytes and used it, but I also found an option in msconfig, so search around in services etc and see where else those dang things put stuff.


It is the one called diagnostic setup. I clicked this and was able to reboot my computer. Malwarebytes got rid of the leftover stuff from the adware but there was still 2 programs that would run. They were in the c:\programdata file. They also constantly ran a process. I was able to delete them once I booted up in diagnostic mode.

Something else to do is to set system restore points before you download anything and then just restore to there, or read the prompts/licencing as they generally tell you they are going to install unless you click no.

JRT does make a nice quick log of everything it got, as well as did a decent job of cleaning up a different time that I ran it.


HitmanPro also did a decent job of cleaning up but it is not free, although you can get a one time free license for it.



That's my update. Thanks for listening!
Oh and a link to all of the programs I used can be found here:
http://malwaretips.com/blogs/adpeakproxy-exe-removal/

Thursday, December 5, 2013

Cleaning

I was doing a bit of cleanup on my PC and ran across a service that did not get uninstalled properly. Normally it would not be necessary to delete a service in my understanding but such things do tend to happen. Here is what I found on deleting services!

1. Run Regedit or Regedt322. Find the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"3. Look for the service there and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).
Alternatively, you can also use command prompt and delete a service using following command:
sc delete < SERVICE name>

or to create, simply type
sc create <SERVICE name>

If you have space in the file path you need to use quotation marks ("). For example:
sc create "MySQL" binpath= "C:\Archivos de programa\MySQL\MySQL Server 5.1\bin\mysqld.exe"

Special thanks to: http://geekswithblogs.net/shahedul/archive/2006/10/13/93984.aspx for the info!

Wednesday, December 4, 2013

Why I am here

So basically I decided that I wanted to compile a resource list of the information I find useful. I have either used it at home or work as I work in an IT department.

If it is a program I will try and provide a link to it as this will make it easier on myself if I am helping a friend.

Today's help comes from:
PENDRIVE: I downloaded a Linux OS on a flash drive that's called ophcrack (http://ophcrack.sourceforge.net), basically it checks the hard drive for users and passwords. It is a most useful tool. Unfortunately you can't get all of it for free, but if it can't find it there is a password reset tool as well.

Basically someone downloaded malware on his work computer while he was on vacation (some sort of scorpion server or something that just gives a bunch of ads and takes you to malware sites). We had to remove the computer from the domain and re-add it. I initially set the computer up but we couldn't remember the login info (as someone threw away the sticky note that had the info on it).