Can I get a credit card if I am illegal but have a valid social security card?

Well, first of all, your social security card is not valid if you are in the country illegally.  Indeed, a SSN is for life but its validity is only as good as long as your stay is authorized by the Department of Homeland Security (DHS).  Having said that, a credit card is a financial relationship between you and the bank issuing it.  While many banks have requirements that you be in the country legally, not all do, and that means that being an undocumented alien in the United States does not necessarily mean that you cannot get credit cards.  You have to understand that a bank is taking a risk when issuing a credit card that the cardholder my not pay the balance.  That also often sets the interest rates.  Banks also look for your credit history, current income, assets, etc. to decide whether to issue a card to anyone, including citizens, permanent residents, and even illegal residents.  For instance, if you have a job (even illegal), a bank account with respectable balance, and assets, you maybe able to get a credit card.  If not, you can always get a secured credit card (your credit limit is equal to whatever amount you deposit in your credit card account ahead of time) that works exactly like a regular credit card (so you can use it rent a car or shop or do anything else people do with a card) and with that over time, you can build a credit history.